Skip to content
Advertisement

subprocess.check_output is too slow on script python but not in interactive python shell

My question is about subprocess.

I’m using subprocess to call an external program, I’ve used the check_output() method in which I pass args as list. what I’ve noticed is that when using check_output() from the interactive shell it takes 3 minutes (which is the correct time for executing the external program in my case [there is no problem if the process stays blocked waiting the response]) however when I’m using the same method with the same params in a python script it can take up to 1hour !.

Is there anyone who faced this situation before? any suggestion ?

For information I’m using Python3.7.3 on a Debian 10.

Thanks is advance

—- edit:

I’ve nothing special in my code

My script is just:

from subprocess import check_output
try:
    #commandList is the programm (external bin) I would excute with its params
    result = check_output(commandList) 
    print(result.decode("latin-1"))
except Exception as e:
    print(e)

Advertisement

Answer

Using subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess. STDOUT, shell=True) fixed the problem.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement