Start application & continue after app exits
p at ulmcnett.com
Thu Jun 9 18:07:47 CEST 2005
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?
testString = "Life is but a dream."
fileName = tempfile.mktemp()
os.system("gedit %s" % 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.
More information about the Python-list