加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 基本的paramiko exec_command帮助

发布时间:2020-12-16 23:41:56 所属栏目:Python 来源:网络整理
导读:我是一个新的paramiko用户,并且很难在paramiko的远程服务器上运行命令.我想导出一个路径,并在后台运行一个名为tophat的程序.我可以使用paramiko.sshclient()登录,但我的exec_command代码没有结果. stdin,stdout,sterr = ssh.exec_command('export PATH=$PATH
我是一个新的paramiko用户,并且很难在paramiko的远程服务器上运行命令.我想导出一个路径,并在后台运行一个名为tophat的程序.我可以使用paramiko.sshclient()登录,但我的exec_command代码没有结果.
stdin,stdout,sterr = ssh.exec_command('export PATH=$PATH:/proj/genome/programs
/tophat-1.3.0/bin:/proj/genome/programs/cufflinks-1.0.3/bin:/proj/genome/programs/
bowtie-0.12.7:/proj/genome/programs/samtools-0.1.16')

stdin,sterr = ssh.exec_command('nohup tophat -o /output/path/directory -I 
10000 -p 8 --microexon-search -r 50 /proj/genome/programs/bowtie-0.12.7/indexes
/ce9 /input/path/1 /input/path/2 &')

没有nohup.out文件,python只是转到下一行,没有错误消息.我也试过没有nohup,结果是一样的.我试图遵循this paramiko tutorial.

我是否正确使用exec_command?

解决方法

我也遇到了同样的问题,在查看了 this article和 this answer之后,我看到解决方案是调用Channel的recv_exit_status()方法.这是我的代码:
import paramiko
import time

cli = paramiko.client.SSHClient()
cli.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
cli.connect(hostname="10.66.171.100",username="mapping")
stdin_,stdout_,stderr_ = cli.exec_command("ls -l ~")
# time.sleep(2)    # Previously,I had to sleep for some time.
stdout_.channel.recv_exit_status()
lines = stdout_.readlines()
for line in lines:
    print line

cli.close()

现在我的代码将被阻止,直到远程命令完成.这个方法在here解释,请注意警告.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读