www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - spawnProcess command-line arguments help

reply "Martin" <martinbbjerregaard gmail.com> writes:
When I use the spawnProcess function in std.process, the command 
line arguments that I provide to the function seem to get 
"quoted". Is there a way to tell the spawnProcess function that I 
want the command line arguments to be non-quoted?

Example:
spawnProcess(["SomePath\\Test.exe"], ["-silent"]);
and the command line becomes: "SomePath\Test.exe" "-silent" (with 
the quotes exaclt like shown).

Unfortunately (for some strange reason), the spawned process only 
responds to non-quoted arguments passed through the command line. 
So the command line should be exactly: "SomePath\Test.exe" -silent

Is there any way to achieve this?
Aug 03 2014
next sibling parent reply "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
 When I use the spawnProcess function in std.process, the 
 command line arguments that I provide to the function seem to 
 get "quoted".
I can't reproduce this on OS X with 2.066rc1 (args are unquoted). Can someone else check Windows? Sounds like a bug to me.
Aug 04 2014
parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Monday, 4 August 2014 at 17:02:27 UTC, Peter Alexander wrote:
 On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
 When I use the spawnProcess function in std.process, the 
 command line arguments that I provide to the function seem to 
 get "quoted".
I can't reproduce this on OS X with 2.066rc1 (args are unquoted).
Arguments on POSIX systems are passed to programs in a different way than on Windows. On POSIX, the arguments are passed as an array of zero-terminated strings (when a command is given as a string, a shell breaks it up into an argument array before running the program). On Windows, the arguments are passed as a string, and are parsed into an array by the executed program (or its language runtime). Although generally Windows programs use the OS function CommandLineToArgvW, they have no obligation to do so, and may implement their own algorithm.
Aug 05 2014
prev sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
 When I use the spawnProcess function in std.process, the 
 command line arguments that I provide to the function seem to 
 get "quoted". Is there a way to tell the spawnProcess function 
 that I want the command line arguments to be non-quoted?

 Example:
 spawnProcess(["SomePath\\Test.exe"], ["-silent"]);
I assume you mean: spawnProcess(["SomePath\\Test.exe", "-silent"]);
 and the command line becomes: "SomePath\Test.exe" "-silent" 
 (with the quotes exaclt like shown).

 Unfortunately (for some strange reason), the spawned process 
 only responds to non-quoted arguments passed through the 
 command line. So the command line should be exactly: 
 "SomePath\Test.exe" -silent

 Is there any way to achieve this?
No, there currently is no way to achieve this using spawnProcess. You could have better luck using spawnShell instead. I would consider such behavior a bug in the application you're trying to run, as it does not perform command-line parsing according to convention (CommandLineToArgvW). It would be possible to enhance spawnProcess and family to only quote arguments which need to be quoted, which would fix this particular case, however of course that can't address every program which parses its command line in a non-standard way.
Aug 05 2014