[fpc-pascal] How to exec() arguments with spaces?
Marco van de Voort
marcov at stack.nl
Fri Nov 26 20:37:52 CET 2004
> I cannot process this way any file that name contains whitespaces.
> Replacing 'my file' with '"my file"', 'my\ file', '"my\ file"'
> has no effect; apart from that exec(myprog, '"myfile"') does not work
> even if filename has no spaces.
> The problem seems to depend on the way of passing arguments to the
> program, not on the program itself: many programs like /bin/cat,
> /bin/gzip, and others behave similarily.
> execv(myprog + ' '+myfile);
> exec(myprog+ ' '+myfile, '');
> result the same.
> The problem is only in Unix. What am I doing wrong?
The harsh answer:
1 using spaces in unix :-)
2 using 1.0.x, while 1.9.x is so much better.
Seriously, it was a bug, it is fixed. To avoid similar problems, 1.9.2 and later
have a function sysutils.executeprocess that avoids it all together by avoiding the
parsing stage and passing arguments separately from the executable name.
sysutils.executeproces('/path to/the file/ with a space',['arg1 arg2','arg2 arg3']);
The exec[v|e|p] functions are renamed to fpexec() and also have this.
More information about the fpc-pascal