最佳答案
这是我的 Python 代码:
import subprocess
subprocess.check_output("ls",shell=True,stderr=subprocess.STDOUT)
import subprocess
subprocess.check_output("yum",shell=True,stderr=subprocess.STDOUT)
第一个 .check_output()
运行良好,但第二个返回:
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
是新的包吗?我怎样才能解决这个问题?