问题
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?
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/11652660/running-wexpect-on-windows