ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Shell bash used in a roslaunch[SOLVED]

asked 2016-10-04 05:09:58 -0600

Kailegh gravatar image

updated 2016-10-05 08:23:20 -0600

Hi! I am having a problem when trying to execute a comand from a roslaunch file which I dont have when running it directly from the shell.

When I execute rosbag play *.bag from the shell it plays every rosbag in the folder.

However when I do the following from a roslaunch file

<arg name="path" default="/home/kailegh/Descargas/Custom/20Jul16/" /> 
<node pkg="rosbag" type="play" name="player" output="screen" args="--clock  $(arg path)*.bag">

It does not work, I obtain the following error

[ INFO] [1475572463.796418638]: Opening /home/kailegh/Descargas/Custom/20Jul16/*.bag
[FATAL] [1475572463.796604618]: Error opening file: /home/kailegh/Descargas/Custom/20Jul16/*.bag

I think the problem is that the roslaunch interpret the * as a normal character, instead of the bash meaning everything. Is there any way to use the '*' in a launch file as it where in the command line?

Thanks a lot from your help!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-04 07:45:12 -0600

In its current form, I don't believe that roslaunch will support this behavior. The roslaunch command line script parses the launch files to figure out arguments, and then eventually opens new subprocesses using the Python subprocess.Popen function. Here are the relevant lines of code. There are many questions online about how to have Popen support globbing (e.g. this one), and the general consensus is that you need to have shell=True (which is often not a good idea... check out this question). The relevant lines in roslaunch don't set shell=True (and they probably shouldn't), and therefore the globbing feature (which is specific to your shell... likely bash) doesn't work.

You could write a simple bash script that handles the globbing for you. For example a starting point would be:

rosbag play --clock $1

Then your launch file could be changed to

  <arg name="path" default="/home/kailegh/Descargas/Custom/20Jul16/" /> 
  <node pkg="your-package" type="" name="player" output="screen" args="$(arg path)*.bag" />

This could give your the functionality that you want.

edit flag offensive delete link more


thanks man,l had thought using a bash script, but what I had in mind was a lot more complicated, that is the perfect solution. Thanks a lot again, problem solved.

Kailegh gravatar image Kailegh  ( 2016-10-05 08:22:56 -0600 )edit

Question Tools



Asked: 2016-10-04 05:09:58 -0600

Seen: 3,934 times

Last updated: Oct 05 '16