【发布时间】:2017-01-20 03:51:21
【问题描述】:
这是我从 paramiko shell 包中使用的 python 代码,返回值 r 是 7 而不是 0。但是,如果我在远程 shell 和echo $? 中运行相同的命令,它会返回0
cmd = "curl --fail -s \"http://localhost:%s/\" > /dev/null" %HTTP_PORT
stdin, stdout, stderr = ssh.exec_command(cmd)
while not stdout.channel.exit_status_ready():
r = stdout.channel.recv_exit_status()
print "r is is %d" %(r) #it returns '7'
【问题讨论】:
-
检查
stdout和stderr中的内容。 -
我无法复制。我尝试了相同的命令集,但得到了
0。你能:1.从cmd中删除--fail -s和> /dev/null,2.打印stdout和stderr吗? -
@whjm,stdin 和 stderr 都与 stdout 相同,都返回 '7'跨度>
-
@hansaplast,全部返回 7
-
删除
--fail -s和print 'stdout: %s, stderr: %s' % (stdout.read(), stderr.read() )。
标签: python python-2.7 ssh paramiko