子进程 check_output 返回非零退出状态 1 [英] Subprocess check_output returned non-zero exit status 1
本文介绍了子进程 check_output 返回非零退出状态 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的python代码:
This is my python code:
import subprocess
subprocess.check_output("ls",shell=True,stderr=subprocess.STDOUT)
import subprocess
subprocess.check_output("yum",shell=True,stderr=subprocess.STDOUT)
第一个 .check_output()
运行良好,但第二个返回:
The first .check_output()
works well, but the second returns this:
Traceback (most recent call last):
File "/usr/lib/x86_64-linux-gnu/gedit/plugins/pythonconsole/console.py", line 378, in __run
r = eval(command, self.namespace, self.namespace)
File "<string>", line 1, in <module>
File "/usr/lib/python3.4/subprocess.py", line 616, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'yum' returned non-zero exit status 1
为什么会这样?是不是因为 ls
是原来的 shell 命令而 yum
是新的包?我怎么解决这个问题?
Why does this happen? Is it because ls
is the original shell command but yum
is the new package? How can I solve this problem?
推荐答案
您启动的命令 yum
已正确执行.它返回一个非零状态,这意味着在处理命令期间发生了错误.您可能想在 yum
命令中添加一些参数来解决这个问题.
The command yum
that you launch was executed properly. It returns a non zero status which means that an error occured during the processing of the command. You probably want to add some argument to your yum
command to fix that.
您的代码可能会以这种方式显示此错误:
Your code could show this error this way:
import subprocess
try:
subprocess.check_output("dir /f",shell=True,stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
这篇关于子进程 check_output 返回非零退出状态 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文