eolas/neuron/cd5cdd66-905b-4f1f-b8e8-3a11ad507325/Invoking_the_shell_in_Python.md
2025-01-13 20:54:49 +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()