有没有人在Windows中运行pexpect.popen_spawn.PopenSpawn()来运行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