简体   繁体   中英

Spawn a new independent process in node.js

Is there any way to spawn a new independent process from the current running script?

I am trying to run a new script from an already running script. The new script should be independent of the one that called it.

You can use the 'detached' option and the unref() method to make child process independent.

const spawn = require('child_process').spawn;

const child = spawn(process.argv[0], ['child_program.js'], {
  detached: true,
  stdio: ['ignore']
});

child.unref();

Ref: Node.js document

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM