我对child-process有点陌生,需要更多的澄清。
我的案子
我正在寻找一种方法来运行/触发一个js文件,作为一个独立/孤立的进程与另一个js文件。不使用直接require或import as,而是从父进程传递某个参数(在我的例子中为数字)到子进程。
parent.js
async function parent () {
/** logic */
/** run/start child.js script with certain (1) argument from logic above /
/** if logic below fails, it won't crash/trigger child, and his job will be finished separately outside async function*/
}child.js
async function child(number) {
/** receive argument from parent.js and execute separately*/
}确定一下,模式:
MAIN THREAD
|
|
run child => CHILD THREAD (receive number arg from main thread)
| |
x | (don't care about error in main thread)
(error) |
END OF M_THREAD |
|
V
(ok, filled)所以我读过一些关于child_process和官方node.js 文档的文章,并且知道有:
模式。我也可以从我的执行单独的国家预防机制任务文件中(例如通过pm2 )进行r,但是在这种情况下,我不知道我应该使用什么,什么适合我的需要。因此,任何建议、解释都会很有帮助,并会得到我投票的回报。
发布于 2020-05-16 21:42:10
您可以在这里检查,并提供如何这样做的简单示例。https://zaiste.net/nodejs-child-process-spawn-exec-fork-async-await/希望它能帮助你。
https://stackoverflow.com/questions/61843497
复制相似问题