Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-11

Re: How to exec() arguments with spaces?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marco van de Voort
to Jan Je/lowicki: I am using fpc 1.0.10 in both Unix and W32. Need to process an external file with…
Show quoted text 13 lines
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. Using 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.

The explanation:

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.

Jan Je/lowicki

Hello,

I am using fpc 1.0.10 in both Unix and W32. Need to process an external file with external binary program:

    exec(myprog, myfile);

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.

Using

    execv(myprog + ' '+myfile);
    exec(myprog+ ' '+myfile, '');

result the same.
The problem is only in Unix. What am I doing wrong?

Sincerely

Jan Jelowicki

------------------------------------------------------------------- Wroclaw University of Agriculture Akademia Rolnicza we Wroclawiu Department of Mathematics Katedra Matematyki -------------------------------------------------------------------

Jan Je/lowicki
Marco van de Voort wrote
The harsh answer: 1 using spaces in unix :-)

this is users' decision, not the programmer's.
Besides, it is legal ;)

2 using 1.0.x, while 1.9.x is so much better.

yes, 1.0.4 was much too buggy for me.
1.0.10 occured quite stable and was enough up to now.

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.

Thanks. This should make me to migrate soon.

Regards,

Jan Jelowicki

------------------------------------------------------------------- Wroclaw University of Agriculture Akademia Rolnicza we Wroclawiu Department of Mathematics Katedra Matematyki -------------------------------------------------------------------