想写一个部署的脚本,
顺序是npm run build
> mv something
> ssh login && upload
因为需要登录远程主机,需要一些交互,发现python的pexpect
挺不错的,可是问题是。
怎么完成第一步的在python中调用npm run build
呢
PHP中文网2017-04-18 10:22:26
Use the paramiko module
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,username,passwd,timeout=5)
stdin, stdout, stderr = ssh.exec_command("npm run build")
out = stdout.readlines()
stdin, stdout, stderr = ssh.exec_command("mv something")
out = stdout.readlines()
...............
ssh.close()
Assume npm has been added to the path environment variable