简体   繁体   English

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

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

I'm using Python to call cscope internally. 我正在使用Python在内部调用cscope For this I'm using subprocess.call . 为此,我使用subprocess.call

The problem is that it's not working without shell=True 问题是没有shell=True它不能工作

The following code works as expected: 以下代码按预期工作:

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

But the following doesn't, it returns with 0 status code, but there is no output 但是以下没有,它返回0状态代码,但没有输出

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

Any ideas as to why the above is happening? 关于为什么会发生这种情况的任何想法?

Don't quote the arguments, the args are passed directly to the process without using the shell when shell=False: 不引用参数,当shell = False时,args直接传递给进程而不使用shell:

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

You should use check_call: 你应该使用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