2014-04-10 134 views
0

我试图构建并运行ssh命令作为“ssh -p 29418 [email protected] gerrit review - 选项1更改,patchnum”基于变化 和patchnum给,任何人都可以提供guidane如何做到这一点?无法构建和运行ssh命令

change = '700293' 
patchnum = '1' 


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

    #ssh -p 29418 [email protected] gerrit review --option 1 change,patchnum 



lock(change,patchnum) 
+2

还要考虑使用的面料,这在Python通过SSH简化运行命令:http://fabric.readthedocs.org/ –

回答

0

你正在寻找一个系统调用 - 使用subprocess模块:

from subprocess import call 

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


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

得到错误TypeError:%d格式:需要一个数字,而不是str –

+0

如何将字符串转换为数字? –

+0

首先,[“如何将字符串转换为数字”](https://www.google.com/search?client=ubuntu&channel=fs&q=how+to+convert+string+to+digit&ie=utf-8&oe=utf- 8)。我不认为这就是你想要做的 - 相反,只是从数字中删除引号。 'change = 700293''而不是'change ='700293'' –