UNPKG

1.19 kBJavaScriptView Raw
1'use strict';
2
3const cp = require('child_process');
4const parse = require('./lib/parse');
5const enoent = require('./lib/enoent');
6
7function spawn(command, args, options) {
8 // Parse the arguments
9 const parsed = parse(command, args, options);
10
11 // Spawn the child process
12 const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
13
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);
17
18 return spawned;
19}
20
21function spawnSync(command, args, options) {
22 // Parse the arguments
23 const parsed = parse(command, args, options);
24
25 // Spawn the child process
26 const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
27
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);
30
31 return result;
32}
33
34module.exports = spawn;
35module.exports.spawn = spawn;
36module.exports.sync = spawnSync;
37
38module.exports._parse = parse;
39module.exports._enoent = enoent;