Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Mr. Alexander

Problem with PowerShell variables in demo-recording script

Recommended Posts

Question about writing a PowerShell script for recording demos, which I'm doing as an exercise: When I record parameters as bare text after the invocation of dsda-doom.exe, using variables to store only their arguments, for example,

&"D:\Path\to\dsda-doom.exe" -iwad $iwad -complevel $complevel -file $pwad"

the program runs as I would expect it to run, but when, for convenience, I try to use variables to store both a parameter and its argument, to store two option switches like -analysis and -levelstat, or to store multiple parameters and switches, for example,

$iwad = "-iwad D:\path\to\iwad.wad"
$pwad = "-file D:\path\to\pwad.wad"
$complevel = "-complevel 9"
$wad_args = "$iwad $pwad $complevel"

$warp = "-warp 01"
$skill = "-skill 4"
$map_args = "$warp $skill"

$record = "-record D:\path\to\demo_folder\demo_name$"
$other_options = "-shorttics -analysis -levelstat"
$demo_args = "$record $other_options"

&"D:\Path\to\dsda-doom.exe" $wad_args $map_args $demo_args

I get an error message like the following: 

Unknown command line option -iwad D:\Games\Doom\doom2.wad -file D:\Games\Doom\wads\doom2\mgwds\machete\macheteFinal.wad -deh D:\Games\Doom\wads\doom2\mgwds\machete\DEHACKED.deh -complevel 9 -warp 01 -skill 4 -shorttics -record D:\Games\Doom\demos\my_demos\machete01-$ -analysis -levelstat

which seems silly on its face. My guess is that it's trying to read all of this as one single parameter, rather than as a parameter and a huge argument, or as several different parameters, their arguments, and some options, but if that's the case, I don't know how to break it all up again except by hand. It could also be that I'm using double quotes where I should use single quotes, or vice versa.

This feels like a "scripter didn't take CS in college" problem, where I've misconstrued the typing and the basic function of what a variable does, storage rather than labeling. It's weird to me that the %additional% variable in the batch files provided in the speed demo subforum, which expects multiple parameters separated by spaces, doesn't seem to suffer from this limitation, but it's probably significant that %additional% doesn't expect a string in single or double quotes. It could also be that I don't understand how PowerShell specifically handles variables-within-variables like this, or how dsda-doom expects parameters and options to be typed and separated from one another. 

Whatever the issue is, I'm sure it's a really basic error, but thanks in advance for any light you might be able to shine on this problem.

Share this post


Link to post

I'm only seeing this now, but it's like a week later, so maybe you've already solved it. Posting anyway, since it might still be helpful to someone out there.

 

 

 

The tl;dr is that powershell is passing three parameters: $wad_args, $map_args, and $demo_args. But what dsda-doom actually wants to receive is 15 parameters: one being "-iwad", then "D:\path\to\iwad.wad", and "-file", then "D:\path\to\pwad.wad", and so on. (I guess this is the standard way to send/receive parameters? I didn't know until now)

 

Quick solution: use Invoke-Expression instead of &.

Invoke-Expression "D:\Path\to\dsda-doom.exe $wad_args $map_args $demo_args"

Basically what it does is treat the whole string as if you typed it on the command line, which means it automatically knows to break up the parameters. (As opposed to & which calls the exe and passes it parameters through the system API or whatever, so you have to be careful what you pass in and how)

 

(If you don't like Invoke-Expression -- fair enough -- you could of course break everything down into the 15 strings and pass them with &. I figure though, for a doom script, that seems like too much hassle)

 

 

 

PS 1: I had some copy/paste issues with the code from your post, there are invisible characters for some reason, which will screw up the script if you leave them around. You probably have it fine in your actual saved script, but just be warned if you copy/paste from here.


PS 2: If you want to tinker around with powershell, you should download echoargs. Put it wherever and then use that path as your exe (i.e. instead of dsda-doom, in this example), it's very handy for testing/troubleshooting. I got my copy from https://ss64.com/ps/call.html

Share this post


Link to post

Thanks very much for your answer! I don't consider it belated at all. The speed demo forum isn't necessarily the best trafficked part of the site, and a fair response to "I'm writing a PowerShell script emulating the standard batch files as an exercise" is "Why not just use the standard batch files rather than insist on PowerShell?"

 

I think I'd known about Invoke-Expression, but had avoided it out of a naïve notion that it would be "less secure" in some amorphous way, despite the lack of any interactive user input. This way of handling the command solved the problem exactly the way I wanted to solve it: Thank you!

Share this post


Link to post

Can you tell me the correct code in the command line for DSDA-DOOM 0.25.6. I use DSDA-DOOM 0.24.3 for record demos but with the latest version of the problem.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×