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()