3 const cp = require('child_process');
4 const parse = require('./lib/parse');
5 const enoent = require('./lib/enoent');
7 function spawn(command, args, options) {
9 const parsed = parse(command, args, options);
11 // Spawn the child process
12 const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
14 // Hook into child process "exit" event to emit an error if the command
15 // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
16 enoent.hookChildProcess(spawned, parsed);
21 function spawnSync(command, args, options) {
22 // Parse the arguments
23 const parsed = parse(command, args, options);
25 // Spawn the child process
26 const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
28 // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
29 result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
34 module.exports = spawn;
35 module.exports.spawn = spawn;
36 module.exports.sync = spawnSync;
38 module.exports._parse = parse;
39 module.exports._enoent = enoent;