3 var cp = require('child_process');
4 var parse = require('./lib/parse');
5 var enoent = require('./lib/enoent');
7 var cpSpawnSync = cp.spawnSync;
9 function spawn(command, args, options) {
13 // Parse the arguments
14 parsed = parse(command, args, options);
16 // Spawn the child process
17 spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
19 // Hook into child process "exit" event to emit an error if the command
20 // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
21 enoent.hookChildProcess(spawned, parsed);
26 function spawnSync(command, args, options) {
32 cpSpawnSync = require('spawn-sync'); // eslint-disable-line global-require
35 'In order to use spawnSync on node 0.10 or older, you must ' +
36 'install spawn-sync:\n\n' +
37 ' npm install spawn-sync --save'
42 // Parse the arguments
43 parsed = parse(command, args, options);
45 // Spawn the child process
46 result = cpSpawnSync(parsed.command, parsed.args, parsed.options);
48 // Analyze if the command does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
49 result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
54 module.exports = spawn;
55 module.exports.spawn = spawn;
56 module.exports.sync = spawnSync;
58 module.exports._parse = parse;
59 module.exports._enoent = enoent;