function spawn(command, args, options) { var parsed; var spawned; // Parse the arguments parsed = parse(command, args, options); // Spawn the child process spawned = cp.spawn(parsed.command, parsed.args, parsed.options); // 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; }
n/a
function parse(command, args, options) { var shebang; var applyQuotes; var file; var original; // Normalize arguments, similar to nodejs if (args && !Array.isArray(args)) { options = args; args = null; } args = args ? args.slice(0) : []; // Clone array to avoid changing the original options = options || {}; original = command; if (isWin) { // Detect & add support for shebangs file = resolveCommand(command); file = file || resolveCommand(command, true); shebang = file && readShebang(file); if (shebang) { args.unshift(file); command = shebang; } // Escape command & arguments applyQuotes = command !== 'echo'; // Do not quote arguments for the special "echo" command command = escapeCommand(command); args = args.map(function (arg) { return escapeArg(arg, applyQuotes); }); // Use cmd.exe args = ['/s', '/c', '"' + command + (args.length ? ' ' + args.join(' ') : '') + '"']; command = process.env.comspec || 'cmd.exe'; // Tell node's spawn that the arguments are already escaped options.windowsVerbatimArguments = true; } return { command: command, args: args, options: options, file: file, original: original, }; }
n/a
function spawn(command, args, options) { var parsed; var spawned; // Parse the arguments parsed = parse(command, args, options); // Spawn the child process spawned = cp.spawn(parsed.command, parsed.args, parsed.options); // 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; }
...
var parsed;
var spawned;
// Parse the arguments
parsed = parse(command, args, options);
// Spawn the child process
spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
// 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 hookChildProcess(cp, parsed) { var originalEmit; if (!isWin) { return; } originalEmit = cp.emit; cp.emit = function (name, arg1) { var err; // If emitting "exit" event and exit code is 1, we need to check if // the command exists and emit an "error" instead // See: https://github.com/IndigoUnited/node-cross-spawn/issues/16 if (name === 'exit') { err = verifyENOENT(arg1, parsed, 'spawn'); if (err) { return originalEmit.call(cp, 'error', err); } } return originalEmit.apply(cp, arguments); }; }
...
parsed = parse(command, args, options);
// Spawn the child process
spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
// 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;
}
module.exports = spawn;
module.exports.spawn = spawn;
module.exports._parse = parse;
...
function notFoundError(command, syscall) { var err; err = new Error(syscall + ' ' + command + ' ENOENT'); err.code = err.errno = 'ENOENT'; err.syscall = syscall + ' ' + command; return err; }
n/a
function verifyENOENT(status, parsed, syscall) { if (isWin && status === 1 && !parsed.file) { return notFoundError(parsed.original, syscall); } return null; }
n/a
function spawn(command, args, options) { var parsed; var spawned; // Parse the arguments parsed = parse(command, args, options); // Spawn the child process spawned = cp.spawn(parsed.command, parsed.args, parsed.options); // 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; }
...
var parsed;
var spawned;
// Parse the arguments
parsed = parse(command, args, options);
// Spawn the child process
spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
// 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 parse(command, args, options) { var shebang; var applyQuotes; var file; var original; // Normalize arguments, similar to nodejs if (args && !Array.isArray(args)) { options = args; args = null; } args = args ? args.slice(0) : []; // Clone array to avoid changing the original options = options || {}; original = command; if (isWin) { // Detect & add support for shebangs file = resolveCommand(command); file = file || resolveCommand(command, true); shebang = file && readShebang(file); if (shebang) { args.unshift(file); command = shebang; } // Escape command & arguments applyQuotes = command !== 'echo'; // Do not quote arguments for the special "echo" command command = escapeCommand(command); args = args.map(function (arg) { return escapeArg(arg, applyQuotes); }); // Use cmd.exe args = ['/s', '/c', '"' + command + (args.length ? ' ' + args.join(' ') : '') + '"']; command = process.env.comspec || 'cmd.exe'; // Tell node's spawn that the arguments are already escaped options.windowsVerbatimArguments = true; } return { command: command, args: args, options: options, file: file, original: original, }; }
n/a