【问题标题】:launch background process with POCO使用 POCO 启动后台进程
【发布时间】:2016-05-26 11:52:29
【问题描述】:

我正在使用 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:(绝望地)我什至尝试了 args 向量上的“&”,但它不起作用!

谢谢,

【问题讨论】:

    标签: c++ qt poco poco-libraries


    【解决方案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;
    }
    

    希望这对其他人有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多