【发布时间】:2015-01-10 11:45:07
【问题描述】:
这是我在 StackExchange 上的第一个查询。如果我的问题已经被提出并回答,请原谅。如果是这样,请指点我。
查询: 我正在尝试建立与板的 telnet 连接,然后想在此之后运行应用程序。我想在整个过程中同时捕获 STDOUT 和 STDERR。下面是我的代码的sn-p
代码片段:
import subprocess
import time
#1. Establish the subprocess
commandlist = ["telnet"] + ["10.11.12.13"]
p = subprocess.Popen(commandlist,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
#2. Give the login name. There is no password
p.stdin.write("root\r")
#3. Adding this for sync to avoid any overlap
time.sleep(1)
#4. Invoke the communicate to execute the application from a specied path on 10.11.12.13 system
stdout, stderr = p.communicate('sh /mnt/path/app\r')
在第 (4) 步,我尝试打印 stdout 和 stderr 的值以查看应用程序“app”是否已运行。不幸的是,它甚至没有执行 'p.communicate()' 行。
如果有人遇到类似问题或知道解决方案,请帮助我解决问题。
谢谢!!
【问题讨论】:
-
it has not even executed the 'p.communicate()' line.。输出是什么? -
@laike9m:下面是输出#STDOUT Trying 10.11.12.13... Connected to 10.11.12.135。 (none) login: root # STDERR 连接被外部主机关闭。
-
@laike9m:我尝试从我的 linux 服务器手动连接到硬件,但没有看到任何此类错误/消息。你对此有什么进一步的建议吗?.. 谢谢.. 而且即使我通过“退出”命令退出硬件,也会出现由外国主机关闭的情况
标签: python subprocess telnet