Windows process ownership trouble

Tim Golden mail at timgolden.me.uk
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:

<code>
import os
import subprocess

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

os.remove ("filename")

</code>

TJG



More information about the Python-list mailing list