Created
June 27, 2024 12:05
-
-
Save Tuanlor207/fd4a5677d67fbb17a68e86d367a99399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require("child_process"); | |
function run(script) { | |
const child = spawn( | |
"node", | |
[ | |
"--trace-deprecation", | |
script | |
], | |
{ | |
cwd: __dirname, | |
stdio: "inherit", | |
shell: true, | |
} | |
); | |
child.on("close", (codeExit) => { | |
if (codeExit !== 0) { | |
console.log(`[ RESTART ] Đang khởi động lại ${script}...`); | |
run(script); | |
} else { | |
console.log(`[ STOP ] Tiến trình con ${script} đã kết thúc!`); | |
} | |
}); | |
child.on("error", function (error) { | |
console.error(`[ ERROR ] Đã xảy ra lỗi với ${script}: ` + JSON.stringify(error)); | |
}); | |
} | |
run("main.js"); | |
//run("like.js"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment