# The difference when using "ros2 launch" and "ros2 run"

**URL:** <https://get-help.theconstruct.ai/t/the-difference-when-using-ros2-launch-and-ros2-run/30869>\
**Category:** ROS2 Navigation Humble\
**Created:** [June 11, 2024, 4:26pm UTC](https://get-help.theconstruct.ai/t/the-difference-when-using-ros2-launch-and-ros2-run/30869 "2024-06-11T16:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NguyenDuyDuc](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/n/8491ac/32.png) [@NguyenDuyDuc](https://get-help.theconstruct.ai/u/NguyenDuyDuc)\
**Post date:** [June 11, 2024, 4:26pm UTC](https://get-help.theconstruct.ai/t/the-difference-when-using-ros2-launch-and-ros2-run/30869/1 "2024-06-11T16:26:31Z")

</div>

Hi,

I can use “ros2 run teleop\_twist\_keyboard teleop\_twist\_keyboard” to move a robot. It works very well  
But I want to run by a launch file for convenience, I use the launch file as:

> import os
> 
> from launch import LaunchDescription  
> from launch\_ros.actions import Node  
> from launch.actions import TimerAction
> 
> from ament\_index\_python.packages import get\_package\_share\_directory
> 
> def generate\_launch\_description():
> 
> ```
> # region teleop_twist_keyboard
> teleop_twist_keyboard_node = Node(
> name = "teleop_twist_keyboard_node",
> package = "teleop_twist_keyboard",
> executable = "teleop_twist_keyboard",
> output = "screen",
> emulate_tty = True,
> )
> # endregion
> 
> return LaunchDescription(
> [
> teleop_twist_keyboard_node
> ]
> )
> 
> ```

 ![Thang_4](https://get-help.theconstruct.ai/uploads/default/original/2X/7/7d57b2af1eccaaf409f934a5c5a2cdb14a988a3f.png)

But an error happens, How to fix it?

Thanks

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [June 12, 2024, 5:04am UTC](https://get-help.theconstruct.ai/t/the-difference-when-using-ros2-launch-and-ros2-run/30869/2 "2024-06-12T05:04:47Z")

</div>

Hi @NguyenDuyDuc ,

The commands `ros2 launch ...` and `ros2 run ...` cannot be interchangeably used.

If a package does not have a launch file, then you cannot `launch` that program.  
You can use `run` command to execute any executables that are available in a package.

Due to a specific dependency in `teleop_twist_keyboard` program that depends on inputs from the terminal, that program does not have a launch file and only a run file. This is because the mentioned dependency is not a ROS2 package and also does not have a ROS2 package. Also, ROS2 does not support inputs from the terminal, which makes it difficult to make a teleop program purely using ROS2 packages / dependencies.

There are some work-arounds to get it working purely with ROS2, but that is quite tedious and not a simple solution (as far as I know), but it is doable.

Therefore, you don’t have a `launch` command for `teleop`. Only `run` command.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [June 17, 2024, 5:05am UTC](https://get-help.theconstruct.ai/t/the-difference-when-using-ros2-launch-and-ros2-run/30869/3 "2024-06-17T05:05:33Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
