我正在使用Python的telnetlib telnet到某台机器并执行少量命令,我想获取这些命令的输出。实时读取telnetlib的输出
那么,究竟目前的情况是 -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
tn.write("command2")
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
#here I get the whole output
现在,我可以得到所有的综合输出sess_op。
但是,我想要的是执行后立即命令2的执行之前,如果我在其他机器的外壳正在努力让Command 1的输出,如下所示 -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
#here I want to get the output for command1
tn.write("command2")
#here I want to get the output for command2
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
它不工作在我的情况! – theharshest 2012-04-25 10:35:58