Rosanswers logo


I would like to do something like this

rostopic echo -p /mytopic > outputfile.txt

with the launch file

Hence, I wrote this in the launch file

<node name="output_topic1" pkg="rostopic" type="rostopic" output="screen" args="echo -p /mytopic > outputfile.txt">

However, it doesn't work and give me an error like this

Usage: rostopic echo [options] /topic

rostopic: error: you may only specify one input topic

[output_topic1-8] process has died [pid 11643, exit code 2, cmd /opt/ros/groovy/lib/rostopic/rostopic echo -p /mytopic > outputfile.txt __name:=output_topic1 __log:=/home/user/.ros/log/edae921e-f970-11e2-be82-14feb5b7467c/output_topic1-8.log].
log file: /home/user/.ros/log/edae921e-f970-11e2-be82-14feb5b7467c/output_topic1-8*.log

Originally posted by Maytheewat on ROS Answers with karma: 215 on 2013-07-30

Post score: 2


2 Answers 2


Rosanswers logo

I haven't used rostopic echo in launch file, but i feel that "type" parameter should have value "echo" and then args should be topic name.

Originally posted by ayush_dewan with karma: 1610 on 2013-07-30

This answer was NOT ACCEPTED on the original site

Post score: 1

Original comments

Comment by pkohout on 2013-07-30:
if you start rostopic via rosrun, the command is "rosrun rostopic rostopic echo " so the type is rostopic and the args should be echo, have you tried it without the "> outputfile.txt" ? Does it work then ?

Comment by ayush_dewan on 2013-07-31:
I haven't tried it but I feel that ">output.txt" is a very generic command used to store the contents published on terminal into a file. Therefore roslaunch is not accepting it.

Comment by Maytheewat on 2013-07-31:
@ayush_dewan that's mean there's no way I could do this in roslaunch? @coon It works without the "> outputfile.txt", I mean it runs without error but I'm not sure if it print anything out to the terminal

Comment by ayush_dewan on 2013-07-31:
@coon@Maytheewat Sorry I am unable to test this right now, so I am not certain about my claim. Since the objective is to store contents of a topic in file, so instead of using rostopic echo write a simple subscriber file ans then store the contents in a file.

Comment by Andrew.A on 2014-05-26:
@Maytheewat Hi, did you eventually manage to get this working? I'm also looking at a similar way to write contents from a published topic to a file.

Comment by atp on 2015-10-29:
I'm interested in this as well.

Comment by Borob on 2016-03-28:
I am also very much interested


Rosanswers logo

Hey guys,

I am very sorry, I haven't check this for a while. I am no longer using ROS. I believe this was working for me three years ago.

  <arg name ="file_name" default="your_bag_file.bag"/>
  <arg name ="dest_path" default="path_to_the_destination"/>
  <arg name ="topic1" default="/topic_name_1"/>
  <arg name ="topic2" default="/topic_name_2"/>
  <arg name ="topic3" default="/topic_name_3"/>
  <arg name ="topic4" default="/topic_name_4"/>
  <node name ="recorder" pkg="rosbag" type="record" output="screen" args="-O $(arg dest_path)/$(arg file_name) $(arg topic1) $(arg topic2) $(arg topic3) $(arg topic4)">

@Druff @atp @Andrew.A

Originally posted by Maytheewat with karma: 215 on 2016-03-28

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Maytheewat on 2016-03-28:
So....I guess I didn't really manage to get .txt file directly out from the topic(s)


Your Answer

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