#! /usr/bin/python
import pexpect
import sys
host = sys.argv[1]
port = sys.argv[2]
command = sys.argv[3]
console = 'console'
child = pexpect.spawn("telnet %s %s" %(host,port),logfile=sys.stdout)
index = child.expect([console,pexpect.EOF],timeout=None)
if (index == 0):
child.sendline("%s" %command)
child.logfile = None
child.interact()
#child.sendline("%s" %command)
else:
print("telnet closed,due to EOF")
child.close(force=True)
如何在不退出telnet的情况下继续执行“ child.interact()”之后的“ child.sendline()”?
或是否有任何方法可以满足要求: 1.远程登录主机 2. telnet会话可以同时处理用户的交互式消息和自动sendline消息。