cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
FN
FN
Level VI

RunProgram with spaces in a powershell command

I am getting an error loading a string that has spaces and I need to pass between double quotes.

 

Names Default to Here(1);

parameter_A = "this has spaces";
parameter_B = "specific.domain.com";

command = "program -Name \!"" || parameter_A ||"\!" -Path \!"" || parameter_B || "\!"";

write(command );
// outputs the expected:
// program -Name "this has spaces" -Path "specific.domain.com"
add_result = RunProgram( Executable( "powershell.exe" ), Options( {"/c", command } ), ReadFunction( "text" ));

The parameter_A   breaks the execution as it thinks there are more arguments passed. Yet, the command works if I copy and paste the output of write in powershell.

 

What am I missing?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: RunProgram with spaces in a powershell command

This has helped me earlier with similar case: Pass quote into Run Program application 

 

escapedquote = "\!\\!"";

 

-Jarmo

View solution in original post

3 REPLIES 3
FN
FN
Level VI

Re: RunProgram with spaces in a powershell command

Names Default to Here(1);

parameter_A = "this has spaces";
parameter_B = "specific.domain.com";

command = "powershell "\!"program -Name '" || parameter_A ||"' -Path '" || parameter_B || '"\!"";

write(command );
// outputs the expected:
// powershell "program -Name 'this has spaces' -Path 'specific.domain.com'"
add_result = RunProgram(
			Executable( "cmd.exe" ),
			Options( {"/C", command } ),
			ReadFunction( "text" ));

This worked for me, not sure if there is a better solution that doesn't use single quotes.

jthi
Super User

Re: RunProgram with spaces in a powershell command

This has helped me earlier with similar case: Pass quote into Run Program application 

 

escapedquote = "\!\\!"";

 

-Jarmo
Craige_Hales
Super User

Re: RunProgram with spaces in a powershell command

here points to a thorough explanation of why the windows command line is so hard to use. The quotation marks don't really do what we think they do. 

I'd mix the apostrophes and quotation marks, as you've done, because it is easier to understand.

 

Craige