Reputation: 6035
I am running an executable from cmd:
*.exe input.inp
I want to run it using python and tried following:
os.system('"*.exe"')
But don't know how to specify input file as well. Any suggestions?
Upvotes: 0
Views: 2855
Reputation: 159
import os
os.system(r'pathToExe.exe inputFileOrWhateverOtherCommand')
Upvotes: 0
Reputation: 6035
I had to launch cmd window and specify input file location from within Python script. This page was really helpful in getting it done.
I used Popen(['cmd', '/K', 'command'])
from above page and replaced '/K'
with '/C'
in it to run and close the cmd window.
Upvotes: 0
Reputation: 1639
import os
from subprocess import Popen, PIPE
p = Popen('fortranExecutable', stdin=PIPE) #NOTE: no shell=True here
p.communicate(os.linesep.join(["input 1", "input 2"]))
For more please refer to:
Using Python to run executable and fill in user input
Upvotes: 1