Escaping and quoting in the commandline
Posted on 2009-02-24
I'm trying to execute a program through ShellExecuteEx, or rather a shell command using cmd /c and am redirecting STDOUT and STDERR to 2 different files which works most of the time.
cmd /c c:\directory\program.exe parameter1 paramter2 1>c:\stdout 2>stderr
This works quite well if there are no spaces in the directories and/or file names. I tried adding double quotes like so, but that didnt work.
cmd /c "c:\directory\program.exe" parameter1 paramter2 1>"c:\stdout" 2>"stderr"
The path to the stdout and stderr files could be anywhere, it is in the subdirectory \temp\ of wherever the exefile happens to be located. What is wrong in the above command?
Alternatively, is anybody aware of a VCL component that runs commands and captures stdout and stderr? preferably in a seperate thread?