-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn.js
28 lines (24 loc) · 949 Bytes
/
spawn.js
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
27
28
const cp = require('child_process');
module.exports = (cmd, args = [], options = {}) => {
process.on('unhandledRejection', err => {
throw err;
});
const result = cp.spawnSync(cmd, args, { stdio: 'pipe', ...options });
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.error(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.error(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
throw new Error('Cannot obtain sentences.')
}
return result.output;
};