简体   繁体   中英

alternatives to PeekNamePipe() with anonymous pipe — WIN32

I have a program that launch another console program as its child process and communicate with it using anonymous pipe. I redirected both its stdin and stdout. The pseudocode is like:

// Create pipes for stdin and stdout
CreatePipe(&std_in_rd, &std_in_wr, NULL, 0);
CreatePipe(&std_out_rd, &std_out_wr, NULL, 0);

// redirection
startup_info.hStdOutput = std_out_wr;
startup_info.hStdInput = std_in_rd;

// create the process
CreateProcess(...);

// send command to the child process.
WriteFile(hWriteStdin, ...);

// receive feedback from the child process.
ReadFile(hReadStdout, ...);

But, the child process's processing the commands needs time, and I don't know how much time I should wait to get its output. I used a loop that calls PeekNamedPipe to examine whether I can read from the pipe, but this method is not good for it consums a lot CPU.

The child process was not written by me and I can't modify its code.

How can I get informed when the child process has finished writing, like a hook?

Thanks.

您应该尝试使用ReadFileEx()从管道异步读取。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM