eolas/neuron/9445c5fd-135c-4b0b-a70c-7a6fd45d9d58/Invoking_the_shell_in_Python.md
2025-04-05 10:32:40 +01:00

402 B

id tags created
cfr4
python
shell
Monday, April 29, 2024

Invoking the shell in Python

import subprocess

try:
    process = subprocess.run(
        ["ls", "-la"],
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        text=True,
    )
    return process.stdout

except subprocess.CalledProcessError as e:
        return e.stderr.strip()