11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst cp = require('child_process'); 41cb0ef41Sopenharmony_ciconst parse = require('./lib/parse'); 51cb0ef41Sopenharmony_ciconst enoent = require('./lib/enoent'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cifunction spawn(command, args, options) { 81cb0ef41Sopenharmony_ci // Parse the arguments 91cb0ef41Sopenharmony_ci const parsed = parse(command, args, options); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci // Spawn the child process 121cb0ef41Sopenharmony_ci const spawned = cp.spawn(parsed.command, parsed.args, parsed.options); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci // Hook into child process "exit" event to emit an error if the command 151cb0ef41Sopenharmony_ci // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16 161cb0ef41Sopenharmony_ci enoent.hookChildProcess(spawned, parsed); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci return spawned; 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cifunction spawnSync(command, args, options) { 221cb0ef41Sopenharmony_ci // Parse the arguments 231cb0ef41Sopenharmony_ci const parsed = parse(command, args, options); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci // Spawn the child process 261cb0ef41Sopenharmony_ci const result = cp.spawnSync(parsed.command, parsed.args, parsed.options); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16 291cb0ef41Sopenharmony_ci result.error = result.error || enoent.verifyENOENTSync(result.status, parsed); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci return result; 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cimodule.exports = spawn; 351cb0ef41Sopenharmony_cimodule.exports.spawn = spawn; 361cb0ef41Sopenharmony_cimodule.exports.sync = spawnSync; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_cimodule.exports._parse = parse; 391cb0ef41Sopenharmony_cimodule.exports._enoent = enoent; 40