【发布时间】:2015-09-26 20:04:15
【问题描述】:
有趣的是,当我尝试使用 bash shell 克隆对象时
ssh -t -i ~/.ssh/security.pem root@xx.xxx.xx.xx 'rm -rf myproject && git clon -b mybranch https://github.com/myproject.git'
一切都很漂亮。
但是当我尝试从 python 子进程调用中做到这一点时,就像
subprocess.check_call("ssh -t -i ~/.ssh/security.pem root@xx.xxx.xx.xx 'rm -rf myproject && git clone -b mybranch https://github.com/myproject.git'", shell=True)
然后我会得到以下错误:
致命:目标路径“myproject”已存在且不是空目录。
回溯(最近一次通话最后一次):
文件“”,第 1 行,在
文件“C:\Python27\lib\subprocess.py”,第 540 行,在 check_call
引发 CalledProcessError(retcode, cmd)
【问题讨论】:
-
运行
check_call("ssh remote-host 'hostname && hostname'", shell=True)或(更好)check_call(["ssh", "remote-host", "hostname && hostname"])以查看两个命令都在远程主机上执行。 Python 不是问题,问题在于您的实际命令(不是您显示的命令)——检查是否有杂散的单引号。
标签: python git ssh subprocess