eolas/neuron/942a9988-f5a6-4ae9-be83-000113c8d4f2/Invoking_the_shell_in_Python.md
2024-11-04 16:36:34 +00: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()