[fpc-devel] TProcess and arguments with quotes

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Sep 5 10:55:11 CEST 2012

On Wed, 5 Sep 2012, Martin wrote:

> From http://bugs.freepascal.org/view.php?id=22801
>> You should not pass quotes. The quotes are only needed in a shell. 
> That is not always possible. And the quotes work on most platforms.

Windows is an exception (as usual). See below.

> I know TProcess changed from a single command-line to a listof arguments. So 
> I couldn't find the User Changes note for this.

You don't need the 'User changes'. It is documented. Press F1.

> An application may however have a list of arguments in a single string (e.g. 
> the IDE ask the user to specify extra arguments. This can be 0, 1 or many)

So ?

> Those must be broken into individual strings.  TProcess does that if send as 
> command line.

No, it does not "break anything down".

On non-windows, each element in the params list is passed as-is in the argv
array; No changes are performed at all.

On windows, each string is surrounded by quotes if there is a space and no
quotes in the string. The string itself is not touched.

This is necessary because the Windows API (CreateProcess) requires a single string:


Note that the API does not mention anywhere how quotes or spaces should be handled.
The reason is that the started application on windows is supposed to handle its own
command-line processing. Unlike Unix, the started application gets the whole
command-line and is supposed to take care of everything by itself. How it
does this is ruled by custom only.

In short: Windows doesn't cater very well for the command-line. 
What quoting may work for application 1, may not work for application 2.


More information about the fpc-devel mailing list