I tried using CreateProcess to run a simple command like hg > test.txt. I tried running the string as a whole (as opposed to separating it into an application name and its parameters). Why does CreateProcess(0, "notepad.exe test.txt", ...) work but CreateProcess(0, "hg > test.txt", ...) does not?
I tried using CreateProcess to run a simple command like hg > test.txt .
Share
You can’t use stdout redirection in the command line passed to
CreateProcess. To redirect stdout you need to specify a file handle for the output in theSTARTUPINFOstructure.You are also making another, more subtle, mistake. The second parameter,
lpCommandLinemust point to writeable memory becauseCreateProcessoverwrites the buffer. If you happen to be using the ANSI version of the function then you will get away with this, but not for the Unicode version.