
So, I have this launch file:
<launch>
<node pkg="some_pkg" type="some_type.py" name="some_name" output="screen" args="--text "some string with spaces"">
</launch>
My python script takes flag --text and then string argument with spaces between quotation marks, like this:
my_python_script.py --text 'some text with spaces'
I have read that in xml I should use " or ' but this does not work, I am getting error error: unrecognized arguments. I also tried using simple quotes - does not work.
what should I write in launch file to pass string argument with spaces to a python script?
Edit: I launch this launch file:
<launch>
<arg name="use_sound" default="false" doc="Use google voice as sound indication"/>
<node if="$(arg use_sound)" pkg="sound_indication" type="makeSoundRequest.py" name="makeSoundRequest" output="screen" args="--text 'please say something' --label mode1">
</node>
</launch>
and terminal output is:
nvidia@tegra-ubuntu:~$ roslaunch turtlebot3_slam_3d sound.launch use_sound:=true
... logging to /home/nvidia/.ros/log/0681ca48-10f0-11ea-8929-00044bc771c7/roslaunch-tegra-ubuntu-11900.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://JETSON_HOSTNAME:45970/
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.14
NODES
/
makeSoundRequest (sound_indication/makeSoundRequest.py)
ROS_MASTER_URI=http://10.42.0.243:11311
process[makeSoundRequest-1]: started with pid [11925]
usage: makeSoundRequest.py [-h] [--text TEXT] [--label [L]] [-p]
makeSoundRequest.py: error: unrecognized arguments: __name:=makeSoundRequest __log:=/home/nvidia/.ros/log/0681ca48-10f0-11ea-8929-00044bc771c7/makeSoundRequest-1.log
[makeSoundRequest-1] process has died [pid 11925, exit code 2, cmd /home/nvidia/catkin_ws/src/sound_indication/scripts/makeSoundRequest.py --text please say something --label mode1 __name:=makeSoundRequest __log:=/home/nvidia/.ros/log/0681ca48-10f0-11ea-8929-00044bc771c7/makeSoundRequest-1.log].
log file: /home/nvidia/.ros/log/0681ca48-10f0-11ea-8929-00044bc771c7/makeSoundRequest-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
and log file written there does not exist.
Originally posted by june2473 on ROS Answers with karma: 83 on 2019-11-26
Post score: 0
Original comments
Comment by Delb on 2019-11-26:
Have you tried using simple quotes instead ?
Comment by june2473 on 2019-11-26:
yes, was not working
Comment by Delb on 2019-11-27:\
was not working
Do you have the same error (unrecognized arguments) or nothing happens ? Also can you provide your code (or just the part that is dealing with the argument) ?
Comment by june2473 on 2019-11-27:
yes, the same problem.
here is that python code that takes arguments, where one of them should be in quotes:
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument( '--text', '-t',
type=str,
dest='text',
help='set message to speech')
parser.add_argument( '--label', '-l',
metavar='L',
type=str,
nargs='?',
dest='label',
help='set label for this message')
parser.add_argument( '-p',
action='store_true',
dest='periodic_flag',
help='set either periodic message or not')
args = parser.parse_args()
print args.text
print args.label
print args.periodic_f
Comment by gvdhoorn on 2019-11-27:
Please do not reply to questions about which specific errors you observe with "the same problem". It does not give us any information.
Show actual errors, together with the commands used that led to those errors.
Single quotes should work, so please show what you did to test that approach and how it failed.
Comment by gvdhoorn on 2019-11-27:
Do not post screenshots to show terminal text. It's just text. Copy-paste it into your question.
Also: please provide updates like your previous two comments as edits to your original question text. Edit the post and append the new information. You can use the edit button/link for that.
I've already added your example .launch file with your question.
Please edit it yourself to remove the link to the screenshot and copy-paste the error message directly from the terminal.
Comment by june2473 on 2019-11-27:
ok, done!