ros2 config_error ai_generated true

ros2 launch: Substitution error: command 'my_script.sh' not found in PATH or launch directory

ID: ros2/ros2-launch-substitution-error-command-not-found

Also available as: JSON · Markdown · 中文
82%Fix Rate
87%Confidence
1Evidence
2024-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Humble active
Iron active
Rolling active

Root Cause

The launch file uses a command substitution (e.g., FindExecutable or ExecuteProcess) to locate an executable, but the executable is not in the system PATH or the launch file's package share directory.

generic

中文

启动文件使用命令替换(如FindExecutable或ExecuteProcess)来定位可执行文件,但该可执行文件不在系统PATH或启动文件的包共享目录中。

Official Documentation

https://docs.ros.org/en/rolling/Tutorials/Intermediate/Launch/Using-Environment-Variables.html

Workarounds

  1. 90% success Ensure the executable is in the PATH. For a shell script in your package, add it to the package's CMakeLists.txt: install(PROGRAMS scripts/my_script.sh DESTINATION lib/${PROJECT_NAME}). Then source the workspace and run: ros2 launch my_package my_launch.py
    Ensure the executable is in the PATH. For a shell script in your package, add it to the package's CMakeLists.txt: install(PROGRAMS scripts/my_script.sh DESTINATION lib/${PROJECT_NAME}). Then source the workspace and run: ros2 launch my_package my_launch.py
  2. 85% success Use FindExecutable substitution with the correct package and executable name. In launch file: from launch.substitutions import FindExecutable; executable = FindExecutable(name='my_script.sh'). Ensure the script is installed in the package's lib directory.
    Use FindExecutable substitution with the correct package and executable name. In launch file: from launch.substitutions import FindExecutable; executable = FindExecutable(name='my_script.sh'). Ensure the script is installed in the package's lib directory.
  3. 75% success If the script is external, add its directory to PATH before launching: export PATH=$PATH:/path/to/script/dir && ros2 launch my_package my_launch.py
    If the script is external, add its directory to PATH before launching: export PATH=$PATH:/path/to/script/dir && ros2 launch my_package my_launch.py

中文步骤

  1. Ensure the executable is in the PATH. For a shell script in your package, add it to the package's CMakeLists.txt: install(PROGRAMS scripts/my_script.sh DESTINATION lib/${PROJECT_NAME}). Then source the workspace and run: ros2 launch my_package my_launch.py
  2. Use FindExecutable substitution with the correct package and executable name. In launch file: from launch.substitutions import FindExecutable; executable = FindExecutable(name='my_script.sh'). Ensure the script is installed in the package's lib directory.
  3. If the script is external, add its directory to PATH before launching: export PATH=$PATH:/path/to/script/dir && ros2 launch my_package my_launch.py

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Even if the script is in the launch directory, the substitution uses the package's share directory, not the source directory. You must install the script via CMake or set the PATH.

  2. 80% fail

    Absolute paths work only on the specific machine they were written for. They break when the workspace is moved or shared with other developers.