eolas/neuron/ac28ab9c-a447-4a90-96b7-2f2694d2a9e4/Invoking_the_shell_in_Python.md
2025-02-22 14:50: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()