eolas/neuron/8a3d2c22-db18-478e-8e4c-1e11b6fe5320/Invoking_the_shell_in_Python.md
2024-12-01 19:37:47 +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()