I am working with ROS and trying to integrate Poco Process for processes management in a ROS QT Interface.
Here's an example of what my node looks like so far :
void My_Interface::gazebo_launch_world()
{
std::string command = "roslaunch";
std::vector<std::string> args;
args.push_back("robot_gazebo");
args.push_back("robot_gazebo.launch");
PocoProcess pp(command, args);
pp.run();
}
int PocoProcess::run()
{
int rc;
try
{
Poco::Pipe outPipe;
Poco::ProcessHandle ph = Poco::Process::launch(command_, args_, 0, &outPipe, 0);
rc = ph.id();
Poco::PipeInputStream istr(outPipe);
Poco::StreamCopier::copyStream(istr, std::cout);
}
catch (Poco::SystemException& exc)
{
std::cout << exc.displayText() << std::endl;
return (-1);
}
return rc;
}
This works fine (launching the process) but, the problem is that my interface freezes while waiting for the process to finish, which is really undesirable.
So, is there anyway that I can launch a POCO Process in the background ?
PS: (Hopelessly) I tried even the "&" on the args vector but it didn't work !
Thanks,
Ok, the solution was to detach the pipes from the output, as it blocks waiting to display it, I changed my code for the following (just commenting the pipes) and it worked.
void My_Interface::gazebo_launch_world()
{
std::string command = "roslaunch";
std::vector<std::string> args;
args.push_back("robot_gazebo");
args.push_back("robot_gazebo.launch");
PocoProcess pp(command, args);
pp.run();
}
int PocoProcess::run()
{
int rc;
try
{
Poco::ProcessHandle ph = Poco::Process::launch(command_, args_);
rc = ph.id();
}
catch (Poco::SystemException& exc)
{
std::cout << exc.displayText() << std::endl;
return (-1);
}
return rc;
}
Hope this will help someone else !