calling a program from Python batch file

Karim Farokhnia karim.farokhnia at gmail.com
Wed Dec 7 11:38:51 EST 2016


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!

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!


More information about the Python-list mailing list