怎么在python中调用npm?

 Daro_olingke_572 发布于 2022-10-25 11:24

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

2 个回答
  • os.system + fabric 或者直接 fabric

    2022-10-26 23:20 回答
  • 用paramiko模块吧

            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()

    假定npm已经添加到path环境变量中

    2022-10-26 23:20 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有