jmborr
jmborr

Reputation: 1295

Poco::Process::launch hangs

launching a process with Poco causes the program to hang:

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();

Irrespective of command 'cmd', Poco forks but the child process doesn't exit, it just hangs in there. Thus, the last line in the code snippet is never executed.

I don't know how to debug this. Any help is very much appreciated!

Upvotes: 0

Views: 1699

Answers (2)

jmborr
jmborr

Reputation: 1295

I just found out that the problem is most likely not related to Poco, but rather to the forking process in itself. My program also forks to run some python code (pythonrun.PyRun_SimpleString) and this child process also hangs.

Upvotes: 1

konsolebox
konsolebox

Reputation: 75548

The child process surely would hang since nothing reads the other end of the pipe that it uses i.e. outPipe and errorPipe. The child process probably should also close the reading end since it's only interesting in writing on it with its messages and error messages.

I also guess that the proper way to run it is through:

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

The parent should also close the write handle before reading it.

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

Upvotes: 0

Related Questions