Execute and Capture one program from another

一笑奈何 提交于 2020-01-02 05:00:22

问题


In win32 programming in C:

Whats the best way to execute a win32 console program within another win32 program, and have the program that started the execution capture the output? At the moment I made the program redirect output to a file, but I am sure I must be able to open some sort of pipe?


回答1:


Use the CreateProcess Win32 API to start the child process.

Pass to it a STARTUPINFO structure with hStdInput, hStdOutput and hStdError handles set to file handles you opened (either real files or memory mapped files should work). You don't need to specify all three, you can redirect only the ones you really need; most common case is hStdOutput.

If you want to communicate with the child process (through hStdInput), you need to wait for it to initialize by calling WaitForInputIdle.



来源:https://stackoverflow.com/questions/593897/execute-and-capture-one-program-from-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!