Choose Language Hide Translation Bar
Community Trekker

Unable to parse speechmarks "" into powershell using RunProgram

Hi, I'm having problems with Executing powershell, for example:

cmd = EvalInsert(
"\[$imageFile = "test"]\");
						rp1 = RunProgram(Executable("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ),

The actual cmd i want to use is more complex but has the same problem with speechmarks. Printing rp1 in the log gives:


"test : The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check 
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ $imageFile = test
+              ~~~~
    + CategoryInfo          : ObjectNotFound: (test:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

 Which implies the line was ran without speechmarks.

How would I ensure speechmarks are ran correctly?

Thanks in advance for any help on this.

0 Kudos
Staff (Retired)

Re: Unable to parse speechmarks "" into powershell using RunProgram

The command line argument needs some additional quotation marks and escaping to make the powershell command line parsing work. (This is the second time I've used powershell, I may be overlooking something...) (Also, this web page syntax coloring is wrong for the square bracket quoting escape.)

command = "\["$imagefile = \"test\";echo $imagefile"]\";
Write( "\!nthe command is:", command ); // write shows it in the log without extra escapes
result = RunProgram(
	executable( "powershell.exe" ), //
	options( command ), //
	readfunction( "text" )//
Show( result );

the command is:"$imagefile = \"test\";echo $imagefile"
result = "test


Here's a screen capture of two tries I made in a CMD window.

Capture.PNGpowershell output in a CMD window

The outer quotation marks make powershell see a single option; the outer quotation marks are removed by CMD before powershell gets the text. In your original example, there were three items powershell received ($imagefile, =, test ) and the outer quotation marks around test were removed by CMD. The outer quotation marks are needed when there are quotation marks or spaces in the arguments.