相关疑难解决方法(0)

subprocess.check_output返回代码

我在用:

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)

但是没有给出任何例子,谷歌没有任何帮助.

python subprocess

42
推荐指数
3
解决办法
6万
查看次数

标签 统计

python ×1

subprocess ×1