Skip to content

subprocess.CalledProcessError misquotes list-style commands #151485

@BenjyWiener

Description

@BenjyWiener

Bug report

Bug description:

import subprocess
subprocess.check_call(['false'])

Output:

Traceback (most recent call last):
...
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.

Expected output:

Traceback (most recent call last):
...
subprocess.CalledProcessError: Command ['false'] returned non-zero exit status 1.

subprocess.CalledProcessError.__str__ manually quotes cmd via "... '%s' ..." instead of "%r". This results in (marginally) confusing error messages when cmd is a list or a string containing '.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-subprocessSubprocess issues.type-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions