Problems when trying to use wexpect for controlling sub-process

465 Views Asked by At

i'm trying to use wexpect on windows machine, and facing issues in the very basic operations. i'm running the following command:

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

and getting the following error:

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

please advise

1

There are 1 best solutions below

0
betontalpfa On

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).