我正在与ROS合作并尝试将Poco Process集成到ROS QT界面中的流程管理中。
以下是我的节点到目前为止的示例:
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;
}
这很好(启动过程),但问题是我的界面在等待进程完成时冻结,这是非常不受欢迎的。
那么,无论如何我可以在后台启动POCO流程吗?
PS :(绝望地)我甚至试过了&#34;&amp;&#34;关于args矢量,但它没有工作!谢谢,
答案 0 :(得分:1)
好的,解决方案是从输出中分离管道,因为它阻止等待显示它,我更改了以下代码(只是评论管道)并且它有效。
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;
}
希望这会帮助别人!