[python-win32] Using os.startfile() for automation [SEC=UNCLASSIFIED]
Andrew MacIntyre
Andrew.MacIntyre at acma.gov.au
Fri Feb 4 00:42:37 CET 2011
[apologies for top post]
All there is to know about os.startfile() is in Python's docs. The only
way to achieve the effect you desire is to do what the "Start Menu..."
action does - explicitly open an instance of the application (and not
all applications will open new instances; some will always open an
existing instance if one exists).
You don't state what version of Python you're using. Assuming it is at
least 2.6, you may wish to investigate the subprocess module and
possibly the multiprocessing module. You will have to explicitly
identify the application required to open the file, as you would with
os.system().
If the application you wish to run supports COM (such as MS Word/Excel
etc do), you could try PythonWin or comtypes, either of which will give
much more control such as saving the file and exiting cleanly.
Other than COM, application automation on Windows requires Windows API
programming to send the necessary messages to application windows - this
is what AutoIt does. I believe that people have written Python code to
do this; googling "python application automation" might give you some
ideas.
-------------------------> "These thoughts are mine alone!" <---------
Andrew MacIntyre Operations Branch
tel: +61 2 6219 5356 Communications Infrastructure Division
fax: +61 2 6253 3277 Australian Communications & Media Authority
email: andrew.macintyre at acma.gov.au http://www.acma.gov.au/
From: python-win32-bounces+andrew.macintyre=acma.gov.au at python.org
[mailto:python-win32-bounces+andrew.macintyre=acma.gov.au at python.org] On
Behalf Of Tony Cappellini
Sent: Friday, 4 February 2011 7:52 AM
To: python-win32 at python.org
Subject: [python-win32] Using os.startfile() for automation
On Windows XP, I'm able to launch the application associated with
file1.xxx.
os.startfile("file1.xxx")
I want to start more instances of the application, so that I can process
several files at the same time.
calling os.startfile("file2.xxx") causes the instance of the application
to also open file2.xxx.
The problem with this is- I have to wait until file1 has finished
processing, before I can start file2.
If, after opening the first instance for file1, I can use the Start
Menu, Program Files, open another instance of the application, I can
then start
processing file2 at the same time as file1, but using a separate
instance.
Is there any other way to invoke startfile() or other function- to force
a new instance of the application to open?
How would I close the application from Python, that was started with
os.startfile()?
Once the application is open, I just want to use File Save As Text, to
get the data into a text file.
Python's app-automation capabilities are kinda weak and not well
documented, so I may resort to AutoIt3.
Thanks
NOTICE: This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all
copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110204/6b78e6ff/attachment-0001.html>
More information about the python-win32
mailing list