我正在使用createprocess和createpipe的组合从cmd读取输入,而不显示cmd窗口。我已经将createprocess和createpipe一起使用,只有1个小问题。这样使用while循环和readfile:(ok是bool类型)
char buf[1024 + 1] = {}; ok = ReadFile(hStdOutPipeRead, buf, 1024, &dwRead, NULL); string temp = buf; string otherTemp; string holdForLineBreak; bool holdOff = false; while (1) { int foundLineBreak = temp.find("\n"); if (foundLineBreak != string::npos) { // string handling stuff here (not relevant to question) } if (foundLineBreak == string::npos) { // string handling stuff here (not relevant to question) } } while (ok == TRUE) { buf[dwRead] = '\0'; OutputDebugStringA(buf); puts(buf); ok = ReadFile(hStdOutPipeRead, buf, 1024, &dwRead, NULL); temp = buf; // make some changes to output and handle it in this loop: while (1) { } } CloseHandle(hStdOutPipeRead); CloseHandle(hStdInPipeWrite); DWORD dwExitCode = 0; GetExitCodeProcess(ProcessInfo.hProcess, &dwExitCode);
读取所有内容后,第二个循环陷入最终的readfile调用中。我知道所有输出都已读取,因为我正在处理和存储它的向量等于我自己在cmd上进行的测试运行。
如何在所有阅读结束时退出readfile?