Start application & continue after app exits

G

Guy Lateur

Hi all,

I was wondering if it would be possible to launch an application, block
until the app exits, and do some cleanup afterwards.

Maybe an example will be clearer: I would like to make a temperary (text)
file, open it with MS Word for the user to edit/layout/print, and then
delete the temp file after the user shuts down Word. Is this feasible?

Thanks,
g
 
P

Paul McNett

Guy said:
I was wondering if it would be possible to launch an application, block
until the app exits, and do some cleanup afterwards.
Maybe an example will be clearer: I would like to make a temperary (text)
file, open it with MS Word for the user to edit/layout/print, and then
delete the temp file after the user shuts down Word. Is this feasible?

Something like:

import os
import tempfile

testString = "Life is but a dream."
fileName = tempfile.mktemp()
print fileName
open(fileName, "w").write(testString)
os.system("gedit %s" % fileName)
os.remove(fileName)

---
Note that I'm on Linux, and instead of launching Word I'm launching an
editor named "gedit". You could likely change that call to winword.exe,
but I haven't tested it on Windows.

Also note that this method of creating tempfiles is technically unsafe,
as it is theoretically possible that another process would create a file
of the same name in the same directory and then try to use it, resulting
in a race condition between the two processes. This is practically
unlikely, however, and I'm a pragmatist.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top