2016-05-26 10 views
0

Ich arbeite mit ROS und versuche, Poco Process für das Prozessmanagement in einem ROS QT Interface zu integrieren.Start Hintergrund Prozess mit POCO

Hier ist ein Beispiel dafür, was sieht mein Knoten wie bisher:

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; 
} 

Dies funktioniert gut (der Prozess startet), aber das Problem ist, dass meine Schnittstelle friert während des Wartens auf den Prozess zu beenden, das ist wirklich unerwünscht.

Also, gibt es trotzdem, dass ich einen POCO-Prozess im Hintergrund starten kann?

PS: (Hoffnungslos) Ich versuchte sogar die "&" auf der args Vektor, aber es hat nicht funktioniert!

Danke,

Antwort

1

Ok, war die Lösung, die Rohre von dem Ausgang zu lösen, wie es blockiert warten, um sie anzuzeigen, ich meinen Code für die folgende (nur die Rohre zu kommentieren) geändert und es funktionierte.

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; 
} 

Hoffe, dass dies jemand anderen helfen wird!

Verwandte Themen