`ExecuteProcess` with `shell=True` gets incorrect exit code from the executed process

Open
#757 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@wjwwood is already working on this.

Since Feb 15, 2024.

Assessment

This issue has not been assessed yet.

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]

Dominant language
Python
Stars
156
Forks
200
Avg merge
2d 11h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ros2/launch

All issues in ros2/launch

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.