使用 python 在不同的文件夹中执行 npm 脚本
Execute npm Script in a different Folder with python
谁能告诉我如何使用 Python 脚本在任何文件夹中执行“npm 运行 start”。但请使用“os”运算符而不是“子进程”。
编辑:
我需要一个 python 脚本,它转到特定文件夹然后执行
“npm 运行 开始”。我该怎么做?
您可以运行在所选文件夹中编码
os.chdir("path/to/folder")
os.system("npm run start")
或
os.system("cd path/to/folder ; npm run start")
os.system("cd path/to/folder && npm run start")
或
subprocess.run("npm run start", shell=True, cwd="path/to/folder")
subprocess.run(["npm", "run", "start"], cwd="path/to/folder")
与subprocess
中的其他方法类似
谁能告诉我如何使用 Python 脚本在任何文件夹中执行“npm 运行 start”。但请使用“os”运算符而不是“子进程”。
编辑: 我需要一个 python 脚本,它转到特定文件夹然后执行 “npm 运行 开始”。我该怎么做?
您可以运行在所选文件夹中编码
os.chdir("path/to/folder")
os.system("npm run start")
或
os.system("cd path/to/folder ; npm run start")
os.system("cd path/to/folder && npm run start")
或
subprocess.run("npm run start", shell=True, cwd="path/to/folder")
subprocess.run(["npm", "run", "start"], cwd="path/to/folder")
与subprocess