Windows process ownership trouble

Tim Golden mail at
Wed Jun 25 21:19:29 CEST 2008

geoffbache wrote:
> Am currently being very confused over the following code on Windows
> import subprocess, os
> file = open("filename", "w")
> try:
>     proc = subprocess.Popen("nosuchprogram", stdout=file)
> except OSError:
>     file.close()
>     os.remove("filename")

Forgot to say: slightly awkward, but you can work around
it like this:

import os
import subprocess

f = open ("filename", "w")
   proc = subprocess.Popen ("blah", stdout=f)
except OSError:
   os.close (f.fileno ())

os.remove ("filename")



More information about the Python-list mailing list