【问题标题】:Why the return value of stdout.channel.recv_exit_status is '7' instead of '0'为什么 stdout.channel.recv_exit_status 的返回值为 '7' 而不是 '0'
【发布时间】: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'

【问题讨论】:

  • 检查 stdoutstderr 中的内容。
  • 我无法复制。我尝试了相同的命令集,但得到了0。你能:1.从cmd中删除--fail -s> /dev/null,2.打印stdoutstderr吗?
  • @whjm,stdinstderr 都与 stdout 相同,都返回 '7'跨度>
  • @hansaplast,全部返回 7
  • 删除--fail -sprint 'stdout: %s, stderr: %s' % (stdout.read(), stderr.read() )

标签: python python-2.7 ssh paramiko


【解决方案1】:

问题是网络服务器在这段时间内没有完全启动。

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 2010-11-14
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    • 2018-09-02
    • 2015-06-21
    • 2012-02-04
    相关资源
    最近更新 更多