behaviour of spawnProcess

Vladimir Panteleev thecybershadow.lists at gmail.com
Sat Nov 25 03:42:33 UTC 2017


On Saturday, 25 November 2017 at 02:32:17 UTC, Fra Mecca wrote:
> I have noticed that whenever j contains a string with a space 
> in it, spawnprocess splits the string into another argument.

That shouldn't happen.

If you are on Windows, note that processes do not see the command 
line as an array of arguments, but as a single string. It is then 
the duty of the process to split up the string into individual 
arguments. If the program lets the C runtime do it by reading 
main's argc/argv, or uses CommandLineToArgvW (which is what C 
runtimes usually use under the hood), things generally work ask 
expected. However, some programs don't do that, and instead use 
their own custom logic for parsing the command line string (such 
as many built-in or standard DOS/Windows commands).

On POSIX, this can be caused if the program you're running is 
itself running another program, and isn't constructing its 
arguments correctly (e.g. it uses the system() function instead 
of an exec* function).


More information about the Digitalmars-d-learn mailing list