执行从另一个捕获一个程序 [英] Execute and Capture one program from another
问题描述
在用C Win32编程:
In win32 programming in C:
请告诉我到另一个Win32程序中执行一个Win32控制台程序,并有开始执行捕获输出程序的最佳方法?目前,我制作的节目将输出重定向到一个文件,但我相信,我一定能够打开一些管道?
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?
推荐答案
使用的 的CreateProcess
的Win32 API来启动子进程。
Use the CreateProcess
Win32 API to start the child process.
传递给它一个 STARTUPINFO
与结构 hStdInput
, hStdOutput
和 hStdError
手柄设置为文件句柄已打开(无论是真实的文件或内存映射文件应该工作)。你并不需要指定所有三个,可以重定向只有你真正需要的那些;最常见的情况是 hStdOutput
。
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
.
如果你想与子进程进行通信(通过 hStdInput
),需要通过调用的 WaitForInputIdle
。
If you want to communicate with the child process (through hStdInput
), you need to wait for it to initialize by calling WaitForInputIdle
.
这篇关于执行从另一个捕获一个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!