Poco :: Process :: launch挂起

时间:2014-08-04 19:25:12

标签: poco-libraries

使用Poco启动进程会导致程序挂起:

std::string cmd = "whatever_you_want_to_write_here";
Poco::Pipe outPipe, errorPipe;
Poco::ProcessHandle ph = Poco::Process::launch(cmd, args, 0, &outPipe, &errorPipe);
rc = ph.wait();

无论命令' cmd',Poco分叉但子进程没有退出,它只是挂在那里。因此,代码片段中的最后一行永远不会被执行。

我不知道如何调试它。非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

我刚刚发现问题很可能与Poco无关,而是与分叉过程有关。我的程序也会运行一些python代码(pythonrun.PyRun_SimpleString),这个子进程也会挂起。

答案 1 :(得分:0)

子进程肯定会挂起,因为没有任何内容读取它使用的管道的另一端,即outPipeerrorPipe。子进程可能也应该关闭阅读结束,因为只有用它的消息和错误消息写在它上面才有意思。

我还猜测运行它的正确方法是:

Poco::ProcessHandle ph = Poco::Process::launch(cmd, args, 0, outPipe.writeHandle(), errorPipe.writeHandle());

父母也应该在阅读之前关闭写句柄。

outPipe.close(CLOSE_WRITE);
errorPipe.close(CLOSE_WRITE);