我在用:
grepOut = subprocess.check_output("grep " + search + " tmp", shell=True)
Run Code Online (Sandbox Code Playgroud)
要运行终端命令,我知道我可以使用try/except来捕获错误但是如何获取错误代码的值?
我在官方文档中找到了这个:
exception subprocess.CalledProcessError
Exception raised when a process run by check_call() or check_output() returns a non-zero exit status.
returncode
Exit status of the child process.
Run Code Online (Sandbox Code Playgroud)
但是没有给出任何例子,谷歌没有任何帮助.