[英]Using PM2 and child_process.exec without opening new command prompts everytime
async function test() {
const shell = require("util").promisify(require("child_process").exec);
const shellResult = await shell("node --version");
console.log(shellResult);
}
test();
在我的程序中,我想做一些類似於上面的 function 的事情。 我使用 PM2 來啟動我的程序。 但是當涉及到這個 function 時,PM2 每次都會打開一個新的 cmd.exe 並在完成后將其關閉,隨着時間的推移會變得很煩人。
有沒有辦法做類似上面的 function 的事情,而不必讓 PM2 每次都打開一個新的 cmd 提示? 或者至少有辦法在后台打開那些 cmd 提示?
額外的信息:
await shell("git pull origin master")
或需要更長時間的東西,那么你實際上可以看到它打開和關閉新的 cmd 提示pm2 start
module.exports = { "apps": [{ "script": "master.js", "node_args": ["--inspect=10000"] }] };
async function test() { const shell = require("util").promisify(require("child_process").exec(cmd,{windowsHide:true}); const shellResult = await shell("node --version"); console.log(shellResult); } test();
您可以使用 windowsHide: true Boolean 來解決這個問題。
參考鏈接: https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.