subprocess wait() waits forever, but os.system returns

Christian Heimes lists at cheimes.de
Wed May 7 16:47:51 EDT 2008


grayaii schrieb:
> There are so many threads on this subject, but I ran across a
> situation on Windows that I can't figure out.
> 
> I'm trying to run this little command-line exe and when I launch like
> this, it hangs:
> 
>>>> import subprocess
>>>> command = r'c:\mydir\foo.exe'
>>>> run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=None, stderr=subprocess.PIPE, env=os.environ, universal_newlines=True)
>>>> returncode = run.wait()  ## HANGS HERE ##

The code blocks because you aren't reading from stdout and stderr. Use
the communicate() method instead of wait().

Christian



More information about the Python-list mailing list