我写了一段代码来在远程服务器上执行git命令,但我从未执行过
Step 1: Login to remote server
Step 2: change dir to git repository
Step 3: execute git clean -fdx command
下面是示例代码
try:
ssh = paramiko.SSHClient()
sssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(dummyipaddress, username="john", password="philips")
except (paramiko.BadHostKeyException,
paramiko.AuthenticationException, paramiko.SSHException) as e:
print str(e)
sys.exit(-1)
try:
channel = ssh.get_transport().open_session()
channel.send("cd /path to git dir"+ '\n')
time.sleep(5)
print channel.recv(1024)
channel.send("git clean -fdx"+'\n')
print chan.recv(1024)
except paramiko.SSHException as e:
print str(e)
sys.exit(-1)
但问题是我可以更改到git存储库,但不能执行git命令
在发送shell命令之前,需要启动shell:
相关问题 更多 >
编程相关推荐