c++ - How do I redirect output to a file with CreateProcess? -


i tried using createprocess run simple command hg > test.txt. tried running string whole (as opposed separating application name , parameters). why createprocess(0, "notepad.exe test.txt", ...) work createprocess(0, "hg > test.txt", ...) not?

you can't use stdout redirection in command line passed createprocess. redirect stdout need specify file handle output in startupinfo structure.

you making another, more subtle, mistake. second parameter, lpcommandline must point writeable memory because createprocess overwrites buffer. if happen using ansi version of function away this, not unicode version.

the unicode version of function, createprocessw, can modify contents of string. therefore, parameter cannot pointer read-only memory (such const variable or literal string). if parameter constant string, function may cause access violation.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -