尝试使用wexpect控制子流程时出现问题

时间:2019-10-03 11:58:32

标签: python wexpect

我正在尝试在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

请告知

1 个答案:

答案 0 :(得分:0)

似乎您正在尝试使用Pycharm的wexpect,它现在是not supported

请在您的IDE外部(从CMD)运行代码。