根据我的代码(它从命令行参数获取主机)
#!usr/bin/python
import sys
import telnetlib
import subprocess
import os
import commands
user = "test"
password = "test"
tn = telnetlib.Telnet(sys.argv[1])
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
pipe = os.popen("pwd","w")
print pipe
pipe3 = os.popen("cd /tftpboot/")
print pipe3
pipe1 = os.popen("pwd","w")
print pipe1
tn.write("exit\n")
print "exit"
这里管道的输出是" /" 而对于pipe1也是" /" 无法通过此脚本更改目录。