[python-win32] Launching an application from python
Tim Golden
tim.golden at viacom-outdoor.co.uk
Thu Apr 22 03:41:22 EDT 2004
>I am a physicist turned programmer for a current project I'm
>working on and
>am rather new to python GUI programming. I would like to know if it is
>possible to launch an application like adobe from my
>application simply by
>programming the commands into a button. I have a few protocols
>that are in
>pdf format and I would like to pull up the protocol in adobe
>as an on the
>fly help while calibrating a linear accelerator using my GUI
>interface. Is
>this possible on windows and how would I go about doing it. I
>know on a Mac
>I can make os.system calls but am unfamiliar with how to do
>this on windows.
Assuming that you have Acrobat Reader installed
(or some equivalent thing) and associated with .pdf
files, the simplest thing is:
<code>
import os
os.startfile (r"c:\temp\blah.pdf")
</code>
os.system will work, but you'll need the full
path to the Acrobat Reader
<code>
import os
ACRORD = r"c:\Program Files\Adobe\Acrobat 5.0\Reader\acrord32.exe"
os.system ('"%s" %s' % (ACRORD, r"c:\temp\blah.pdf"))
</code>
You could -- and I mention this merely for completeness --
use os.startfile to launch the reader without a file. The
slight subtlety is that os.startfile (which uses the ShellExecute
api under the covers) honours AppPath shortcuts which
applications can use to link a name (such as "acrord32") to
a longer executable path:
<code>
import os
os.startfile ("acrord32")
</code>
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-win32
mailing list