By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

external file closed

P: n/a
I am opening a file using os.start('myfile.pdf') from python. How can I
know when the user has closed the file so I can delete it? Thanks.

Oct 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Oct 17, 12:43 pm, "kilnhead" <bumt...@gmail.comwrote:
I am opening a file using os.start('myfile.pdf') from python. How can I
know when the user has closed the file so I can delete it? Thanks.
I assume you mean os.startfile. There is no way to do this directly.
os.startfile simply hands off the call to the OS and doesn't provide
anything to track anything after that. Since you won't know what
program handled the file association, you couldn't watch for an
instance of that to start up and detect when it exits. Even if you
could, it wouldn't be reliable as in the case of PDF's and Adobe
Acrobat Reader, the user could close the document, but not the
application, so your script would never delete the file in question.

If anyone can think of a way to do this, it would be interesting to see
how it's done.

--
Jerry

Oct 17 '06 #2

P: n/a

Jerry wrote:
On Oct 17, 12:43 pm, "kilnhead" <bumt...@gmail.comwrote:
I am opening a file using os.start('myfile.pdf') from python. How can I
know when the user has closed the file so I can delete it? Thanks.

I assume you mean os.startfile. There is no way to do this directly.
os.startfile simply hands off the call to the OS and doesn't provide
anything to track anything after that. Since you won't know what
program handled the file association, you couldn't watch for an
instance of that to start up and detect when it exits. Even if you
could, it wouldn't be reliable as in the case of PDF's and Adobe
Acrobat Reader, the user could close the document, but not the
application, so your script would never delete the file in question.

If anyone can think of a way to do this, it would be interesting to see
how it's done.

--
Jerry
os.system('myfile.pdf') will give return code upon closing. This can
also be done using the subprocess module with poll().

Oct 17 '06 #3

P: n/a
You may be able to use os.popen()
kilnhead wrote:
I am opening a file using os.start('myfile.pdf') from python. How can I
know when the user has closed the file so I can delete it? Thanks.
Oct 17 '06 #4

P: n/a
I think the win32all extension includes the findwindow() fuction, so
you could make a loop that looks for the window name (or class if it
takes that) of the pdf. You can also loop through a list of running
processes looking for whatever the process name is. Note that both of
these have serious loopholes, such as if there is more than one pdf
open.

Cheers,
Jordan

utabintarbo wrote:
Jerry wrote:
On Oct 17, 12:43 pm, "kilnhead" <bumt...@gmail.comwrote:
I am opening a file using os.start('myfile.pdf') from python. How can I
know when the user has closed the file so I can delete it? Thanks.
I assume you mean os.startfile. There is no way to do this directly.
os.startfile simply hands off the call to the OS and doesn't provide
anything to track anything after that. Since you won't know what
program handled the file association, you couldn't watch for an
instance of that to start up and detect when it exits. Even if you
could, it wouldn't be reliable as in the case of PDF's and Adobe
Acrobat Reader, the user could close the document, but not the
application, so your script would never delete the file in question.

If anyone can think of a way to do this, it would be interesting to see
how it's done.

--
Jerry

os.system('myfile.pdf') will give return code upon closing. This can
also be done using the subprocess module with poll().
Oct 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.