I have an executable (evapo.exe) which has to be called with an input file (inputs.prj), usually I do it using windows command prompt by just typing c:\myfiles\evapo inputs.prj (of course both the executable and input file located in myfiles folder)
Now I want to be able to do the same thing using python. Other similar questions here on SO suggested to use wexpect since other methods such as subprocess do not work when the executable askes for other informations to run (for my case the information being the input file). i tried:
import wexpect wexpect.run(r'c:\myfiles\evapo.exe')
and python hangs..., please help me if anyone has an idea how i can combine the exe and input file as I do it using cmd.
preguntado el 04 de julio de 12 a las 00:07
wexpect if all information you want to pass is a file name:
from subprocess import check_call check_call(r'c:\myfiles\evapo.exe inputs.prj')
I guess wexpect is a python port of pexpect and behaves similarly but works on windows.
I checked on the following: http://www.jjoseph.org/files/led_calibration/wexpect.py
If that is the case then any of the examples for
pexpect Deberia trabajar.
run() command should be used when you just want to collect output. This does not work when you want to interact and provide inputs.
if you want to send the inputs, you will need to use spawn() function.
See the example in the code. Here the command asks for an input which is sent across by wexpect
child = wexpect.spawn('some command') child.expect ('Password:') child.sendline (mypassword)
Just go through following answers on pexpect and substitute it with wexpect.
- La forma más sencilla de ejecutar el script de espera desde python
- Necesita poca ayuda con el módulo pexpect
- Necesita poca ayuda con la interacción esperada
And also for windows following port has been suggested as working one: