Ask Your Question

how to pass a string argument that contains white space?

asked 2011-06-30 16:47:04 -0500

Kei Okada gravatar image

I have a program that takes string as an argument, such as

$ ./say "hello world"

and would like to invoke this program from roslaunch.

Here is an example of the launch file:

 < launch>
   < node name="say" pkg="say" type="say" args='\"hello world\"' />
 < /launch>

When I check the command line argument with

$ roslaunch say.launch --args /say

the output is

PYTHONPATH=/opt/ros/diamondback/ros/core/roslib/src /home/k-okada/ros/diamondback/say/say "hello world" __name:=say

and this is ok to me. but when I try to start this program from launch file by

$ roslaunch say.launch

the argument corrupts. It seems that the roslaunch divide string arugment into each words as written in the log file

[roslaunch][INFO] 2011-07-01 13:35:10,808: process[hoge-1]: args[[u'/home/k-okad
a/ros/diamondback/say/say', '"hello', 'world"', u'__name:=

Changing the launch file to

 < launch>
   < node name="say" pkg="say" type="say" args='\"hello\ world\"' />
 < /launch>

worked, but if there are other solution, I would like to know that.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-07-01 05:50:48 -0500

kwc gravatar image

The args string is interpreted by shlex, which uses the POSIX command-line parsing rules. Thus, the arg string should be identical to whatever you would have typed in a shell.

I did a test on my own setup and the following works:

args='"hello world"'


args='"hello world'"

i.e. you don't need to escape the quotes.

The reason why the --args works is that the terminal does not represent separate arguments, and roslaunch simply prints back the arguments to the screen with a space separator. I could attempt to escape --args so that it preserved the argument separation, though this would have the side-effect of making the output of --args harder to read.

edit flag offensive delete link more


thanks, this works for me too.
Kei Okada gravatar image Kei Okada  ( 2011-07-01 15:11:43 -0500 )edit

answered 2011-06-30 17:05:23 -0500

Kei Okada gravatar image

Also, I think this would be a similar question. json_prolog requires JAVA_HOME environment and rosjava package provides nice script( to set JAVA_HOME. Here is my launch file and

< launch>
  < node name="json_prolog_jsk_semantic_map" pkg="json_prolog" type="json_prolog"
        launch-prefix="JAVA_HOME=`rosrun\ rosjava\`" />
< /launch>
roslaunch hoge.l --args /json_prolog_jsk_semantic_map | bash

works, but

roslaunch hoge.l


edit flag offensive delete link more


That's not a similar question. Please post it separately, with more details.
Mac gravatar image Mac  ( 2011-06-30 17:08:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-06-30 16:47:04 -0500

Seen: 9,658 times

Last updated: Jul 01 '11