Executing DOS (yes, DOS) program from within Python?

cmkl cmkleffner at gmx.de
Tue Oct 7 04:51:38 EDT 2003


baf at texas.antispam.net (Ben Fairbank) wrote in message news:<3f8205c0.5059254 at news.houston.sbcglobal.net>...
> I am preparing a Python program that has to call a DOS statistical
> program that asks the user to give an input file name and an output
> file name from the console, it then reads input, processes the data,
> and writes the output file (quaint, no?).  I want to run it without
> keyboard input, but rather using Python statements to specify the same
> input and output files every time it runs.  (It is a compiled Pascal
> program and changing its I/O and recompiling is not really an option.)
> I have looked through Hammond and Robinson without finding any
> suggestions; can a reader tell me where the proper Python way to do
> that is documented?
> 
> Thanks,
> 
> Ben Fairbank

Is it possible to run your application from commandline or 
from within a batch file WITHOUT manual user interaction?
In this case you can start the application with os.system or 
os.popen2.
I prefer "winprocess.py" in the \Lib\site-packages\win32\demos  
folder (but you need to install win32all)

Maybe it is not possible to run the application without user
interaction, so you can give Mick Trent's "process.py" a try.
(see http://starship.python.net/crew/tmick/)
This module has a ProcessProxy class for handling this issue.

"SendKeys" is another option to emulate keybord events on the 
Windows desktop and send it to an application window. Not a 
nice solution for this kind of problem, but a working one.
(http://www.rutherfurd.net/python/sendkeys/index.html)

Carl




More information about the Python-list mailing list