Ticket #4115 (closed defect: fixed)
wxExecute fails to escape spaces in argv on MS Windows
| Reported by: | bdimm | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | wxMSW | Version: | |
| Keywords: | Cc: | bdimm | |
| Blocked By: | Patch: | yes | |
| Blocking: |
Description
The "argv" version of wxExecute, i.e. the one with signature:
wxExecute(char **, int, wxProcess *)
does not quote the strings or escape the spaces in the strings passed in the first argument on Windows, but it does on Linux. This creates problems for writing code that works on both platforms.
For example:
char *argv[] = {"myprog", "without quotes", "\"with quotes\"", NULL};
wxExecute(argv, wxEXEC_ASYNC, this);
On Linux, myprog will be invoked with argv:
0 -> myprog
1 -> without quotes
2 -> "with quotes"
In contrast, Windows will have argv:
0 -> myprog
1 -> without
2 -> quotes
3 -> with quotes
On Windows, the single argument "without quotes" is split into two arguments by the time myprog receives it, because wxWidgets 2.8.4 on Windows doesn't quote the arguments or escape spaces. If you try to remedy this problem by quoting all arguments before calling wxExecute, your code will no longer work on Linux since myprog will receive extraneous quotes.
I would argue that the Linux behavior is the correct one -- argv indicates which items should be considered to be separate arguments, so wxWidgets should handle any platform-dependent manipulations like escaping spaces or adding quotes (and escaping any quotes that those quotes enclose) that are necessary. The Windows version should be changed to behave consistently with the Linux version.

