CreateProcess "cmd.exe /c" with output redirection

Viewed 22

I wrote a shell GUI application that starts a console application with CreateProcessW, then terminates and leaves the console application running.

Now I would like to turn on the debug output of the console application and redirect its output to a file.

I could organize pipes to redirect the output, but I want that the GUI application terminates and leaves things alone. So I decided to launch cmd.exe and use its standard redirection symbols:

"C:\Windows\System32\cmd.exe" /c "C:\Program Files (x86)\ConsoleProgram\ConsoleProgram.exe" -debug > "R:\log.txt" 2>&1

It writes to the log.txt file:

"C:\Program" is not recognized as an internal or external command, operable program or batch file.

When I use "/C/Program Files (x86)/ConsoleProgram/ConsoleProgram.exe" instead, it writes:

system could not find the path specified

1 Answers

Try with -debug inside the double quotes. Everything else seems to be correct in your script.

Instead of this

"C:\Windows\System32\cmd.exe" /c "C:\Program Files (x86)\ConsoleProgram\ConsoleProgram.exe" -debug > "R:\log.txt" 2>&1

modify as shown below:

"C:\Windows\System32\cmd.exe" /c "C:\Program Files (x86)\ConsoleProgram\ConsoleProgram.exe -debug" > "R:\log.txt" 2>&1

Note: This will not work since it is Unix style: "/C/Program Files (x86)/ConsoleProgram/ConsoleProgram.exe"

Related