From: Keith MARSHALL <keith.marshall@to...> - 2005-04-15 10:01:48
Angus Leeming wrote:
> I'm at something of a loss here. The attached code creates a child
> process using 'spawnvp'. The child simply echos the argv data that it
> It appears that spawnvp is splitting the input data incorrectly. The
> "C:\\Documents and Settings\\Ang.." arg is being split at the spaces
> and passed as four separate args.
> This is a problem with spawnvp rather than with the receiving sh.exe;
> exactly the same thing happens if I spawn a python script.
> I see nothing in the spawnvp docs about this nor have I found any
> mention of such problems on a quick google search, so I'm pretty
> confused. Any ideas?
Yes. The problem is that argument quoting is broken, for *all* of
Microsoft's implementations of the `spawn' and `exec' families of
functions; embedded spaces, backslashes, and double quotes confuse
them horribly; single quotes aren't recognised in any sense that
might be expected by a user coming from a *nix background.
As you correctly deduced, in your follow up post, you need to quote
all arguments correctly, using *double* quotes only, and escape all
backslashes. If you are able to use GPL code, I can let you have a
derivative of the solution Jeff Conrad and I worked up to solve this
for the GNU Troff project; we created a system of wrappers for the
`spawn' and `exec' functions, which transparently supply whatever
quoting is required. (I'll post it anyway, but I need an hour or
two package it in a usable format).
Keith MARSHALL wrote:
> If you are able to use GPL code, I can let you have a
> derivative of the solution Jeff Conrad and I worked up to solve this
> for the GNU Troff project;
Thanks, Keith, but I plan to move to CreateProcess instead. Code
written. Further stress testing needed.
Incidentally, if you're interested, I wrote a formally-correct parser
of a unix-style command. Integration of this working parser into the
rest of the code to spawn/monitor the child is a work-in-progress.
Equivalent URL: http://tinyurl.com/4c4v9