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

Start application & continue after app exits

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Guy Lateur wrote:
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.
--
Paul McNett
http://paulmcnett.com

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.