开发者

How to create a child process with redirected only the input

To create a child process in pipe, there is a great example in MSDN. When your parent process is a console application, you could handle the child process stdout by the following way easily:

HANDLE my_own_pipe_read_handle = 0, my_own_pipe_write_handle = 0;
// create pipe
CreatePipe( &my_own_pipe_read_handle, &my_own_pipe_write_handle, NULL, 0 );
// create STARTUPINFO
STARTUPINFO siStartInfo;
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
// fill in STARTUPINFO
siStartInfo.cb = sizeof(STARTUPINFO); 
siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
siStartInfo.hStdInput = my_own_pipe_read_handle;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;

My question is: what should I give to hStdError and hStdOutput value, when the host process is a Win32 (WinM开发者_JAVA百科ain) application (so it has no standard output and standard error)? How would you do it?

Finally I solved my project on TCP/IP, many thanks for help. The current solution is future prof. :)


I believe you will have to provide a pipe for the output as well. This can lead to some tricky situations - I suggest you read Raymond Chen's recent posts on the subject.


Make sure that you don't add the STARTF_USESTDHANDLES flag in your STARTUPINFO structure. The handles will be ignored.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜