gpt4 book ai didi

python - 在 Windows 中使用 pexpect.popen_spawn.PopenSpawn() 运行 telnet 实例

转载 作者:太空宇宙 更新时间:2023-11-04 11:57:08 33 4
gpt4 key购买 nike

有没有人幸运地运行 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

最佳答案

使用 plink 解决了这个问题:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

代替

C:\Windows\System32\telnet localhost {}

我用过

plink.exe -telnet localhost -P {}

关于python - 在 Windows 中使用 pexpect.popen_spawn.PopenSpawn() 运行 telnet 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53887070/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com