0

I opened a temporary file with the following code in Python:

p=subprocess.Popen(tempFileName,shell=True)

 processId=p.pidcode

I want to remove that temporary file, when that file is closed. I wanted to remove the file with the PiD of opening process, but the problem is even when I close that file pid still exists.

 p=subprocess.Popen(tempFileName,shell=True)
 processId=p.pid

Are there any other ways to remove that temporary file?

2
  • 7
    Popen doesn't open a temporary file. It runs an external program and provides references to its standard input/output/error. Even so, the value of the pid attribute isn't going to change simply because the process that used to use that ID has completed.
    – chepner
    Commented Sep 19, 2013 at 13:58
  • 2
    Erm, subrocess.Popen doesn't open a file - check the docs Commented Sep 19, 2013 at 13:58

1 Answer 1

6

Why not use tempfile? It should be portable and can remove files without you bothering with it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.