English 中文(简体)
渠道:recv_exit_status in paramiko总会恢复因援引而执行的第一名指挥官的返回法。
原标题:channel.recv_exit_status in paramiko always returns the return code of the first command executed over invoke_shell

I am getting some discrepancy in the return code below. May be I am not using in the proper way. Every-time I print the return code, it prints the same as the first one has returned. Do I need to reset the return code. I mean in the following example, I am getting the return code as 2 for both the commands. Now when I interchange both the commands, I mean replace ls -al;exit with ls -al file_not_exist;exit and vice versa, it prints return code 0. Each time it prints the same return code as the first one has returned.

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
ssh.connect( localhost , username= sam , password= mypassword )

channel = ssh.invoke_shell()
channel.send( ls -al file_not_exist;exit
 ) #Sending to list a file which doesn t exist
time.sleep(3)
print("My 1st command exit status is: ", channel.exit_status_ready())
print("My 1st command return code is: ", channel.recv_exit_status())

channel.send( ls -al;exit
 )
time.sleep(3)
print("My 2nd command exit status is: ",channel.exit_status_ready())
print("My 2nd command return code is: ",channel.recv_exit_status())

我需要印刷每个指挥部的返回代码。 请帮助我如何解决这一问题?

问题回答

s后退的状态是沙丘进程执行的遥控指挥状态。 只有在以下情况下,才能取得一种退约状态:invoke_shell(,即壳体本身的退船状态。 只有在这种环境下,才知道撤离指挥状态。

你们要么需要找回并打上手脚(双管是可变的<代码>$?),要么独立执行你的指挥系统(exec_command()。

See also: Can I get the exit code of a command executed in a subshell via ssh?





相关问题
Download file from SFTP server in Python Paramiko

I am using Python Paramiko to retrieve/search file from an SFTP server. I get all file in the directory. What I need is specific file from that directory. How do I get it?

Shutting Down SSH Tunnel in Paramiko Programmatically

We are attempting to use the paramiko module for creating SSH tunnels on demand to arbitrary servers for purposes of querying remote databases. We attempted to use the forward.py demo that ships with ...

Problem originating SSH tunnels from python

The object is to set up n number of ssh tunnels between satellite servers and a centralized registry database. I have already set up public key authentication between my servers so they just log right ...

How do I launch background jobs w/ paramiko?

Here is my scenario: I am trying to automate some tasks using Paramiko. The tasks need to be started in this order (using the notation (host, task)): (A, 1), (B, 2), (C, 2), (A,3), (B,3) -- ...

Paramiko的无效关键错误

我试图为部署我的“灰色”网络应用而建造法布里斯,而Paramiko则在我的私人“RSA”钥匙上玩笑。 我在6个月中成功地利用了我的关键,因此我知道这很好。 案件......

python libraries for ssh handling

I m going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands ...

Python SSH paramiko issue - ssh from inside of ssh session

import paramiko client = paramiko.SSHClient() client.load_system_host_keys() ip = 192.168.100.6 client.connect(ip, username= root , password= mima ) i, o, e = client.exec_command( apt-get install ...

Solving thread cleanup on paramiko

I have an automated process using paramiko and have this error: Exception in thread Thread-1 (most likely raised during interpreter shutdown) .... .... <type exceptions.AttributeError >: ...

热门标签