繁体   English   中英

没有shell = True,Python subprocess.call不起作用

[英]Python subprocess.call doesn't work without shell=True

我正在使用Python在内部调用cscope 为此,我使用subprocess.call

问题是没有shell=True它不能工作

以下代码按预期工作:

import subprocess
subprocess.call("cscope -d -L0'temp'", shell=True)

但是以下没有,它返回0状态代码,但没有输出

import subprocess
subprocess.call(["cscope", "-d", "-L0'temp'"])

关于为什么会发生这种情况的任何想法?

不引用参数,当shell = False时,args直接传递给进程而不使用shell:

subprocess.call(["cscope", "-d", "-L0","temp"])

你应该使用check_call:

from subprocess import check_call

check_call(["cscope", "-d", "-L0", "temp"])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM