digitalmars.D.learn - behaviour of spawnProcess
Fra Mecca <me francescomecca.eu> writes:
I have this snipper of code: auto pid = spawnProcess([exe, j], po.readEnd, pi.writeEnd, std.stdio.stderr); where exe is the executable name and j is argv. I have noticed that whenever j contains a string with a space in it, spawnprocess splits the string into another argument. In this way, even if I can use an array to index the arguments, the behaviour is very different from execvp or subprocess.call. Is this desired? Or is it a bug?
Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
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).