exception de sous-processus python
try:
subprocess.check_output(...)
except subprocess.CalledProcessError as e:
print(e.output)
Clumsy Cassowary
try:
subprocess.check_output(...)
except subprocess.CalledProcessError as e:
print(e.output)
with open("stdout.txt","wb") as out, open("stderr.txt","wb") as err:
subprocess.Popen("ls",stdout=out,stderr=err)
>>> import shlex, subprocess
>>> command_line = input()
/bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
>>> args = shlex.split(command_line)
>>> print(args)
['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd', "echo '$MONEY'"]
>>> p = subprocess.Popen(args) # Success!