Python subprocess not working without shell = True

I use Python to call cscopeinternally. For this I use subprocess.call.

The problem is that it does not work without shell=True

The following code works as expected:

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

But the following fails, it returns with a status code 0, but there is no way out

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

Any ideas as to why this is happening?

+4
source share
1 answer

Do not quote arguments; arguments are passed directly to the process without using a shell when shell = False:

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

You should use check_call:

from subprocess import check_call

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

All Articles