eolas/zk/Invoking_the_shell_in_Python.md
2024-04-29 18:00:04 +01:00

450 B

id title tags created
cfr4 Invoking_the_shell_in_Python
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 json.loads(process.stdout)

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