-
-
Notifications
You must be signed in to change notification settings - Fork 497
Expand file tree
/
Copy pathspawnTask.js
More file actions
26 lines (23 loc) · 699 Bytes
/
spawnTask.js
File metadata and controls
26 lines (23 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const { spawn } = require('child_process');
/**
* spawns a child process to run a given node.js script
*/
module.exports.runChildProcess = function (scriptName, options) {
const childProcess = spawn('node', [scriptName], options);
childProcess.stdout.on('data', data => {
console.log(`${data}`);
});
childProcess.stderr.on('data', data => {
console.log(`error: ${data}`);
});
return new Promise((resolve, reject) => {
childProcess.on('error', (error) => {
console.log(`error: ${error.message}`);
reject(error);
});
childProcess.on('close', code => {
console.log(`child process exited with code ${code}`);
resolve(code);
});
});
};