`ExecuteProcess` with `shell=True` gets incorrect exit code from the executed process
Open
@wjwwood is already working on this.
Since Feb 15, 2024.
- Dominant language
- Python
- Stars
- 155
- Forks
- 182
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Bug report
Required Info:
- Operating System: Ubuntu 22.04
- Installation type: binaries
- Version or commit hash: 1.0.4
- DDS implementation: n/a
- Client library (if applicable): n/a
Steps to reproduce issue
Create test.py
import time
import sys
try:
time.sleep(100)
except KeyboardInterrupt:
print("Exiting due to interrupt")
sys.exit(0)
In the same directory, create test.launch.py
from launch import LaunchDescription
from launch.actions import ExecuteProcess
def generate_launch_description():
return LaunchDescription([
ExecuteProcess(
cmd=['python3', './test.py'],
shell=True,
output='screen',
)
])
Run ros2 launch test.launch.py. After a few seconds, type Ctrl-C.
Expected behavior
The test.py process to exit cleanly.
Actual behavior
It shows an error saying the process has died
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [python3-1]: process started with pid [1524803]
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[python3-1] Exiting due to interrupt
[ERROR] [python3-1]: process has died [pid 1524803, exit code -2, cmd 'python3 ./test.py'].
Additional information
Running python3 test.py itself and interrupting with Ctrl-c results in a 0 exit code, so it's not clear why the behavior is different when run through launch. This also only happens if shell=True. When shell=False or omitted, I get
[INFO] [python3-1]: process started with pid [1524563]
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[python3-1] Exiting due to interrupt
[INFO] [python3-1]: process has finished cleanly [pid 1524563]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.