1

我正在尝试在 Windows 机器上使用 wexpect,并在非常基本的操作中遇到问题。我正在运行以下命令:

import wexpect
child = wexpect.spawn('cmd.exe')
child.send('dir')

并收到以下错误:

C:\Users\Administrator\PycharmProjects\testProject\venv\Scripts\python.exe 
C:/Users/Administrator/PycharmProjects/testProject/test.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/testProject/test.py", line 3, in <module>
child.send('dir')
File "C:\Users\Administrator\PycharmProjects\testProject\venv\lib\site-packages\wexpect.py", line 
1810, in send
c = self.wtty.write(s)
File "C:\Users\Administrator\PycharmProjects\testProject\venv\lib\site-packages\wexpect.py", line 
2128, in write
wrote = self.__consin.WriteConsoleInput(records)
**pywintypes.error: (6, 'WriteConsoleInput', 'The handle is invalid.')**

Process finished with exit code 1

请指教

4

1 回答 1

0

It seems you are trying to use wexpect from Pycharm, which is not supported right now.

Please run your code outside from your IDE (from a CMD).

于 2019-12-07T14:43:54.410 回答