我正在尝试将下面的ssh命令转换成python代码,我可以转换成python,但是python代码没有给出任何输出,所以我想我没有正确地转换它,特别是布尔“和”logic..can有人指出这里有什么问题吗?
ssh -p 29418 company.com gerrit query --current-patch-set --commit-message --files 'status:open project:platform/code branch:master label:Developer-Verified=1 AND label:Code-Review>=1'Python代码:
with open(timedir + "/ids.txt", "wb") as file:
check_call("ssh -p 29418 company.com "
"gerrit query --commit-message --files --current-patch-set "
"status:open project:platform/code branch:master label:Developer-Verified=1 AND label:Code-Review>=1 |"
"grep refs |"
"cut -f4 -d'/'",
shell=True, # need shell due to the pipes
stdout=file) # redirect to a file发布于 2013-01-20 15:43:49
>=1可能会被解释为重定向到=1文件,这就是ids.txt文件中没有输出的原因。
在check_call()中使用的字符串没有引用gerrit的参数。将其与第一个引用参数的命令进行比较。
您可以使用pipes.quote()将字符串转义为shell的单个命令行参数。
发布于 2013-01-20 15:45:01
使用Paramiko通过ssh连接
import paramiko
ssh = paramiko.SSHClient()
ssh.connect('127.0.0.1', username='xxx',
password='xxx')然后,您可以使用subprocess python模块来执行系统调用。
https://stackoverflow.com/questions/14422378
复制相似问题