Skip to content

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

@azeey

Description

@azeey

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]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions