Rosanswers logo


With the

ros2 bag record

command I can easily start recording data to a bag file. Is it possible the start recording in with a launch file? I would like to start some nodes from this launch file and start recording, as well.

Thanks for your help.

Originally posted by tlaci on ROS Answers with karma: 48 on 2020-01-14

Post score: 0


1 Answer 1


Rosanswers logo

You should be able to launch the ros2 bag record command as an executable. For example, recording all topics:

import launch

def generate_launch_description():
    return launch.LaunchDescription([
            cmd=['ros2', 'bag', 'record', '-a'],

and the XML equivalent if you are using ROS Eloquent or newer:

  <executable cmd="ros2 bag record -a" output="screen" />

Originally posted by jacobperron with karma: 1870 on 2020-01-17

This answer was ACCEPTED on the original site

Post score: 3

Original comments

Comment by justinberi on 2021-05-25:
Is anyone else experiencing an issue with this? When I ctrl-c the launch bag always dies.

The launch file:

def generate_launch_description():
    return LaunchDescription([
    ExecuteProcess(cmd=['ros2', 'bag', 'record', '-a'], output='screen', log_cmd=True),

On ctrl-c:

[ERROR] [ros2-2]: process has died [pid 40507, exit code 2, cmd 'ros2 bag record -a'].

And the tables in the sqlite database seem corrupt.

Comment by ljaniec on 2022-03-25:
@justinberi I think that better place to ask for it would be a GitHub issue there: https://github.com/ros2/rosbag2 You can prepare your MWE and error description etc. and maybe get answers directly from maintainers


Your Answer

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