使用Paramiko时环境变量的差异 [英] Environment variable differences when using Paramiko
本文介绍了使用Paramiko时环境变量的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过终端(在Mac上)连接到SSH,并运行Paramiko Python脚本,由于某种原因,会话的行为似乎有所不同.
I am connecting to SSH via terminal (on Mac) and run a Paramiko Python script and for some reason, the sessions seem to behave differently.
PATH
环境变量在两种情况下都不相同
The PATH
environment variable, is different in both cases
这是我运行的代码:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('host', username='myuser',password='mypass')
stdin, stdout, stderr =ssh.exec_command('echo $PATH')
print (stdout.readlines())
有人知道为什么环境变量不同吗?
Any idea why the environment variables are different?
该如何解决?
推荐答案
使用Channel
对象而不是SSHClient
对象解决了我的问题.
Working with the Channel
object instead of the SSHClient
object solved my problem.
chan=ssh.invoke_shell()
chan.send('echo $PATH\n')
print (chan.recv(1024))
有关更多详细信息,请参见文档
For more details, see the documentation
这篇关于使用Paramiko时环境变量的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文