无法构造和运行ssh命令

时间:2014-04-10 23:36:04

标签: python ssh

我正在尝试构建并运行ssh命令为“ssh -p 29418 servacc@company.com gerrit review --option 1 change,patchnum”基于更改 和patchnum,谁能提供guidane如何做到这一点?

change = '700293'
patchnum = '1'


def lock (change,patchnum):
    #Construct ssh command

    #ssh -p 29418 servacc@company.com gerrit review --option 1 change,patchnum



lock(change,patchnum)

1 个答案:

答案 0 :(得分:0)

您正在寻找系统调用 - 使用subprocess模块:

from subprocess import call

def lock(change,patchnum):
    #Construct ssh command
    #ssh -p 29418 servacc@company.com gerrit review --option 1 change,patchnum
    call(["ssh -p 29418 servacc@company.com gerrit review --option 1 %d,%d" %(change,patchnum)],shell=True) 


change = 700293
patchnum = 1 
lock(change,patchnum)