python子进程执行bash脚本

1
2
3
4
5
6
7
8
from subprocess import check_output, STDOUT
cmd = "some cmd"

try:
cmd_stdout = check_output(cmd,stderr=STDOUT, shell=True).decode()
except Exception as e:
print(e.output.decode()) # print out the stdout messages up to the exception
print("a") # To print out the exception message

参考

subprocess

How to catch exception output from Python subprocess.check_output()?

作者

Wei Mo

发布于

2022-03-11

更新于

2024-06-03

许可协议

评论