calling a program from Python batch file

Stephen Tucker stephen_tucker at
Wed Dec 7 14:55:34 EST 2016

This might be totally irrelevant, but, if (a) the data to be read by the
program during a given run is known when the program is run/launched, (b)
that data is purely textual and (c) that data can be read by the program
from the stdin channel, then my idea is (1) before the launch, put that
data into a file named, say, inputfile.dat, and then (2)  launch the
program with a command like

call program.bat <inputfile.dat

Moreover, if the program needs to output textual data, and can do so using
stdout, then the data can be sent to another file named, say,
outputfile.dat as follows:

call program.bat <inputfile.dat >outputfile.dat

Finally, if the program can read its data from a given file and possibly
needs to output its data, again, to a named file, and those files' names
can be read from the parameters to the call, then

call program.bat inputfile.dat outputfile.dat

can be used.

On Wed, Dec 7, 2016 at 6:23 PM, Michael Torrie <torriem at> wrote:

> On 12/07/2016 10:59 AM, John Gordon wrote:
> > In <f9d6e83d-d8e7-4245-a02f-9065572632a9 at> Karim
> Farokhnia <karim.farokhnia at> writes:
> >
> >> Hi there,
> >
> >> I am writing a batch file in Python. The batch file, in part, calls a
> >> program named "oq-console.bat" to run. Then once the program comes up
> >> (it looks like windows CMD), I need the batch file to type some commands
> >> to make it run (just like I would do it by myself).
> >
> > If you need to start up a program, provide interactive input to it, and
> > perhaps examine its interactive output, then you want the "pexpect"
> module:
> >
> >     Pexpect is a pure Python module for spawning child applications;
> >     controlling them; and responding to expected patterns in their
> output.
> >     Pexpect allows your script to spawn a child application and control
> it
> >     as if a human were typing commands.
> >
> >
> Does Pexpect work on Windows?
> In the OP's case it looks like the standard in pipe is sufficient.
> --

More information about the Python-list mailing list