2017-12-15 10:56:14 -08:00
|
|
|
'use strict';
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
const cp = require('child_process');
|
|
|
|
const parse = require('./lib/parse');
|
|
|
|
const enoent = require('./lib/enoent');
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
function spawn(command, args, options) {
|
|
|
|
// Parse the arguments
|
2021-05-08 05:39:21 -07:00
|
|
|
const parsed = parse(command, args, options);
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
// Spawn the child process
|
2021-05-08 05:39:21 -07:00
|
|
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
// Hook into child process "exit" event to emit an error if the command
|
|
|
|
// does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
|
|
enoent.hookChildProcess(spawned, parsed);
|
|
|
|
|
|
|
|
return spawned;
|
|
|
|
}
|
|
|
|
|
|
|
|
function spawnSync(command, args, options) {
|
|
|
|
// Parse the arguments
|
2021-05-08 05:39:21 -07:00
|
|
|
const parsed = parse(command, args, options);
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
// Spawn the child process
|
2021-05-08 05:39:21 -07:00
|
|
|
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
2017-12-15 10:56:14 -08:00
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
// Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
2017-12-15 10:56:14 -08:00
|
|
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = spawn;
|
|
|
|
module.exports.spawn = spawn;
|
|
|
|
module.exports.sync = spawnSync;
|
|
|
|
|
|
|
|
module.exports._parse = parse;
|
|
|
|
module.exports._enoent = enoent;
|