想写一个部署的脚本,顺序是npm run build > mv something > ssh login && upload因为需要登录远程主机,需要一些交互,发现python的pexpect挺不错的,可是问题是。怎么完成第一步的在python中调用npm run build呢
npm run build
mv something
ssh login && upload
pexpect
业精于勤,荒于嬉;行成于思,毁于随。
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
os.system + fabric or directly fabric
Use the paramiko module
Assume npm has been added to the path environment variable
os.system + fabric or directly fabric