Ask Your Question
0

how to pass a string argument that contains white space?

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

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:=
say']]

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
0

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

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"'

or

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

Comments

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

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

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(find-javahome.sh) to set JAVA_HOME. Here is my launch file and

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

works, but

roslaunch hoge.l

doesn't.

edit flag offensive delete link more

Comments

That's not a similar question. Please post it separately, with more details.
Mac gravatar imageMac ( 2011-06-30 17:08:58 -0600 )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

Stats

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

Seen: 8,358 times

Last updated: Jul 01 '11