ejecutar un ejecutable usando wexpect

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

If you run it "by just typing c:\myfiles\evapo inputs.prj", then executable doesn't "ask for other information to run", it gets all it needs from the command line arguments. But you're not passing any arguments. Without knowing what evapo does it's impossible to be sure, but my bet is that, in the absence of any arguments, it reads stdin, and that's why it hangs. -

2 Respuestas

No necesitas 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')

Respondido 09 ago 17, 13:08

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.

And also for windows following port has been suggested as working one:

contestado el 23 de mayo de 17 a las 13:05

@Eric Gentil: I hope this helps - pifunc

:it seems there are two modules: wexpect and winpexpect. are they different? - eric gentil

@EricGentil: Yes. Both seems to be a port of pexpect. Also If your program expect filename as command line argument then my solution is not valid. I was under impression that this programs requires user input like typing password. - pifunc

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.