Search code examples
pythonc++ros

ROS CPP equivalent of Python subprocess.call() with shell=True


The following code snippet works fine in ROS Indigo (Python 2.7)-

import subprocess
subprocess.call(["rosnode", "kill", "my_node"], shell=True)

However, I am looking for ROS CPP equivalent of above function. The system command isn't working since the specified command is supposed to be executed through the shell.


Solution

  • .system() method that's it.

    Before, I used this method in a ROS package, as following to publish a topic manually:

    system("rostopic pub -1 /tilt_scan_controller/command std_msgs/Float64 -- 0.0"); 
    

    In your situation will be:

    system("rosnode kill <your-node-name>");