你想围绕做它的其他方式。制作一个执行命令(或你的python脚本)的python脚本并将输出写入终端。
下面是这样的python脚本的例子,在我的情况下,执行一个命令,调整我的笔记本电脑的声音。
#!/usr/bin/python
import paramiko
import sys
def sshConnect():
HOST = "ip"
USER = "user"
KEYF = "/home/pi/.ssh/id_rsa"
ssh = paramiko.SSHClient()
key = paramiko.RSAKey.from_private_key_file(KEYF)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "[*] Connecting..."
ssh.connect(hostname=HOST, username=USER, pkey=key)
print "[+] Connected!"
return ssh
def setVolume(ssh, volume):
command = 'osascript -e "set Volume %s" ' % (volume)
print "Executing %s" % (command)
stdin,stdout,stderr = ssh.exec_command(command)
print stdout.read() #this prints the result in the terminal
errors = stderr.read()
if errors:
print errors
ssh.close()
print "[+] Disconnected"
def main(volume):
setVolume(sshConnect(), volume)
if __name__ == "__main__":
main(sys.argv[1])
你可以使用子模块,用来捕获一个命令的输出 – Kallz