calling a program from Python batch file

Bob Gailer bgailer at gmail.com
Wed Dec 7 12:31:28 EST 2016


On Dec 7, 2016 11:40 AM, "Karim Farokhnia" <karim.farokhnia at gmail.com>
wrote:
>
> 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).
>
> I need the batch file does the whole things automatically, I mean calls
the program, types in commands and press enter!

Try using the stdin argument of subprocess.
>
> So far, I have used the below Python codes in my batch file to do that;
>
>
> import subprocess
>
> subprocess.call(["C:\Program Files (x86)\OpenQuake
Engine\oq-console.bat", "oq --run", "job.ini"])
>
>
> Note that the first string is the program, and the last two are the
commands which needs to be typed in.
>
> It pulls up the program well, but doesn't type in the commands to make it
to run.
>
>
> Any ideas on how I can get the program to run the commands as well?
>
> Thank you!
> --
> https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list