Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Executing DOS (yes, DOS) program from within Python?

Reply
Thread Tools

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

 
 
Ben Fairbank
Guest
Posts: n/a
 
      10-07-2003
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
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      10-07-2003
Ben Fairbank wrote:
>
> 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?


This isn't a DOS-specific or Windows-specific issue actually, so that
might be why the Win32 book didn't help so much. I think you are
looking for the likes of os.popen() and the popen2 module.

Is it possible, however, that the program can take input redirected
from a file? If instead of typing the commands you can create a
file containing the exact same text, including CR/LF, and then execute
the program with redirected input, as in the following example, then
you might find it easier to write the commands out to a file and then
execute your program with os.system():

yourprog.exe <inputfile

If that works, then os.system("yourprog.exe <inputfile") would work,
provided your script creates "inputfile" ahead of time.

-Peter
 
Reply With Quote
 
 
 
 
cmkl
Guest
Posts: n/a
 
      10-07-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Ben Fairbank) wrote in message news:<(E-Mail Removed)> ...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW this program is executing plz explain the program manish sahu C Programming 11 02-13-2010 09:07 PM
Executing a JAVA Program from a JAVA Program Shadow123 Java 0 08-11-2008 07:13 PM
Executing a DOS program from within Python Randy Kreuziger Python 1 03-16-2006 07:10 PM
Running MS-DOS within a c++ program (Code) Mike C++ 7 01-25-2006 03:28 AM
Executing DOS commands from ASP.NET Daniel Portal ASP .Net 2 11-19-2005 01:49 AM



Advertisments