I am running an executable from cmd:
我从cmd运行可执行文件:
*.exe input.inp
I want to run it using python and tried following:
我想使用python运行它并尝试以下:
os.system('"*.exe"')
But don't know how to specify input file as well. Any suggestions?
但是不知道如何指定输入文件。有什么建议?
2 个解决方案
#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
使用Python运行可执行文件并填写用户输入
#2
I had to launch cmd window and specify input file location from within Python script. This page was really helpful in getting it done.
我必须启动cmd窗口并在Python脚本中指定输入文件位置。这个页面非常有助于完成它。
I used Popen(['cmd', '/K', 'command'])
from above page and replaced '/K'
with '/C'
in it to run and close the cmd window.
我在上面的页面中使用了Popen(['cmd','/ K','command'])并将'/ K'替换为'/ C'来运行并关闭cmd窗口。
#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
使用Python运行可执行文件并填写用户输入
#2
I had to launch cmd window and specify input file location from within Python script. This page was really helpful in getting it done.
我必须启动cmd窗口并在Python脚本中指定输入文件位置。这个页面非常有助于完成它。
I used Popen(['cmd', '/K', 'command'])
from above page and replaced '/K'
with '/C'
in it to run and close the cmd window.
我在上面的页面中使用了Popen(['cmd','/ K','command'])并将'/ K'替换为'/ C'来运行并关闭cmd窗口。