search

Home  >  Q&A  >  body text

怎么在python中调用npm?

想写一个部署的脚本,
顺序是npm run build > mv something > ssh login && upload
因为需要登录远程主机,需要一些交互,发现python的pexpect挺不错的,可是问题是。
怎么完成第一步的在python中调用npm run build

迷茫迷茫2777 days ago626

reply all(2)I'll reply

  • PHP中文网

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:22:26

    os.system + fabric or directly fabric

    reply
    0
  • Cancelreply