0
$\begingroup$

Rosanswers logo

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:

 
   
 

When I check the command line argument with

$ roslaunch say.launch --args /say
</pre>
the output is
<pre>
PYTHONPATH=/opt/ros/diamondback/ros/core/roslib/src /home/k-okada/ros/diamondback/say/say "hello world" __name:=say
</pre>
and this is ok to me.
but when I try to start this program from launch file by
<pre>
$ 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

 
   
 

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


Originally posted by Kei Okada on ROS Answers with karma: 1186 on 2011-06-30

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by kwc with karma: 12244 on 2011-07-01

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Kei Okada on 2011-07-01:
thanks, this works for me too.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.