0

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?

Ibe
  • 5,615
  • 7
  • 32
  • 45
  • possible duplicate of [how to execute a python script file with an argument from inside another python script file](http://stackoverflow.com/questions/4230725/how-to-execute-a-python-script-file-with-an-argument-from-inside-another-python) – Tui Popenoe May 06 '15 at 04:53
  • Possible duplicate of [Using Python to run executable and fill in user input](https://stackoverflow.com/questions/21522267/using-python-to-run-executable-and-fill-in-user-input) – Spooky Sep 26 '18 at 21:15

3 Answers3

1
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

Community
  • 1
  • 1
Abhishek Dey
  • 1,601
  • 1
  • 15
  • 38
0

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.

Ibe
  • 5,615
  • 7
  • 32
  • 45
0
import os
os.system(r'pathToExe.exe inputFileOrWhateverOtherCommand')
user3376851
  • 149
  • 10