我試圖在Windows上使用pexpect.popen_spawn.PopenSpawn打開telnet連接,因爲pexpect.spawn僅在Linux平臺上可用。我已經在Linux上用pexpect.spawn測試了相同的python腳本,並且它工作正常。但是,我無法在Windows上使用pexpect.popen_spawn.PopenSpawn打開telnet。以下錯誤WindowsError:[錯誤2]系統找不到pexpect.popen_spawn.PopenSpawn中指定的文件
console = popen_spawn.PopenSpawn(mycommand)
File "C:\Python27\lib\site-packages\pexpect\popen_spawn.py", line 45, in __ini
t__
self.proc = subprocess.Popen(cmd, **kwargs)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
線pexpect.popen_spawn.PopenSpawn("C:/Windows/System32/telnet.exe <IP> <PORT>")
顯示現在TELNET.EXE可在C:/在Windows/System32下,我已經成功地測試了使用上的命令提示符下的Telnet相同的命令。我究竟做錯了什麼?任何想法?我正在使用python 2.7
print os.environ ['COMSPEC']打印爲C:\ windows \ system32 \ cmd.exe –