有没有人幸运地运行 pexpect.popen_spawn.PopenSpawn() 以在 Windows 中运行 telnet?
请注意,我已经从 Windows 启用了“Telnet 客户端”功能,因为我只需在命令行中键入“telnet”即可从命令行正常运行“telnet”。
import sys
import pexpect
from pexpect.popen_spawn import PopenSpawn
EXPECTED_PROMPT = "> "
def test():
telnet_port=4444
if sys.platform.startswith('win'):
telnet = pexpect.popen_spawn.PopenSpawn(
"C:\Windows\System32\telnet localhost {}".format(telnet_port),
timeout=120,
logfile=sys.stdout)
telnet.expect(EXPECTED_PROMPT)
return telnet
if __name__ == "__main__":
telnet = test()
当我尝试运行上面的代码时,出现以下错误:
Traceback (most recent call last):
File ".\test.py", line 26, in <module>
telnet = test()
File ".\test.py", line 20, in test
logfile=sys.stdout)
File "C:\Python27\lib\site-packages\pexpect\popen_spawn.py", line 53, in
__init__
self.proc = subprocess.Popen(cmd, **kwargs)
File "C:\Python27\lib\subprocess.py", line 394, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 644, in _execute_child
startupinfo)
WindowsError: [Error 5] Access is denied
我是一名优秀的程序员,十分优秀!