[Tutor] Responding to a request for input from a MS-DOS program

Alan Gauld alan.gauld at btinternet.com
Wed Oct 11 22:39:24 CEST 2006

Hi Jeff,

> I want to use Python to run an old MS-DOS program that doesn't
> accept arguments when launched. I have to open the program first,
> then it will ask me for the name of another program
> I want to bypass the human input, because I have over
> 100 files I want processed, and I can use Python to iterate through
> each file in turn

You need to look at the subprocess module and the examples that
replace the older popen functions.

You will find more info including examples of both popen and
subporocess in my tutorial under the OS topic in the
Applications Section

Since you are new to this you might want to read the whole topic,
or for more directed help scroll down to the Manipulating Processes
heading. Unfortunately I just noticed I don't give any excample of
writing to a process(in response to a prompt) which is something I
should fix...

Finally, for more sophisticated scenarios there is a module
implementing the expect program in Python, but I suspect that will
be overkill here.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list