1

I have installed wexpect on Windows 7. Now, when I am trying to run any command, I am getting the below error. I am using MKS toolkit, so ls is a valid command.

>>> import pexpect
>>> pexpect.run('ls ')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\winpexpect-1.5-py2.7.egg\pexpect.py", line
219, in run
child = spawn(command, maxread=2000, logfile=logfile, cwd=cwd, env=env)
File "C:\Python27\lib\site-packages\winpexpect-1.5-py2.7.egg\pexpect.py", line
429, in __init__
self._spawn (command, args)
File "C:\Python27\lib\site-packages\winpexpect-1.5-py2.7.egg\pexpect.py", line
516, in _spawn
raise ExceptionPexpect ('The command was not found or was not executable: %s
.' % self.command)
pexpect.ExceptionPexpect: The command was not found or was not executable: ls.

Can some one please help?

cokeman19
  • 2,405
  • 1
  • 25
  • 40
sarbjit
  • 3,786
  • 9
  • 38
  • 60
  • Did you add the location of `ls` to your path? – BrtH Jul 25 '12 at 15:03
  • yes it is there in my system path. Is there any special path for python? – sarbjit Jul 26 '12 at 03:03
  • yes, the PYTHONPATH. See http://cs.simons-rock.edu/python/pythonpath.html – BrtH Jul 26 '12 at 21:02
  • The title refers to Wexpect, but the code displayed and the tag show that this is not Wexpect but Pexpect, and while they are similar in some ways, how well they work on Windows is supposed to be their biggest difference. See https://stackoverflow.com/questions/1042778/can-i-use-expect-on-windows-without-installing-cygwin/1042975#1042975 – Post169 Oct 09 '19 at 17:56

2 Answers2

0

Very late reply, but I also faced this problem recently.

Many reasons for failure or probably, wexpect.py needs modification (at least for my case)

Pl check pexpect_error.txt file generated in the same directory of wexpect.py file.

It forks 'python.exe' hence 'python.exe' must be in path (no other name of exe is permitted).

You must be in the same directory of wexpect.py (lib file name must be wexpect.py not pexpect.py) when you are executing your py script.

The cmd (with extension .exe/.com/.bat), must be working at your windows/shell command prompt . Check that (eg actually in Windows when we run 'ls', it is actually running ls.exe/com, in py script, mention as 'ls.exe')

Last but not least: In my case, console window for Window OS creation was failing (found from pexpect_error.txt), hence I changed below

line 2397, make Y coordinate of rect small instead of 70 eg 24 worked for me

ndas
  • 217
  • 2
  • 7
0

UPDATE

The issue has already solved in v2.3.4.


Brief:

Add .exe at the end of the executable:

>>> import pexpect
>>> pexpect.run('ls.exe')

Details:

The root cause of the problem placed in the enumerated which command (method). This method searches the executable in the filesystem. Here is the critical snippet from my wexpect:

# ...
for path in pathlist:
    f = os.path.join(path, filename)
    if os.access(f, os.X_OK):
        return f
return None
# ...

This code appends the parameter of run() as filename and returns it if it is a valid and executable path. Note, that Windows (unlike Linux) executables ends with *.exe

betontalpfa
  • 3,454
  • 1
  • 33
  • 65