|
|
@ -28,13 +28,11 @@ const { createPromise, |
|
|
|
const debug = util.debuglog('child_process'); |
|
|
|
|
|
|
|
const uv = process.binding('uv'); |
|
|
|
const spawn_sync = process.binding('spawn_sync'); |
|
|
|
const Buffer = require('buffer').Buffer; |
|
|
|
const Pipe = process.binding('pipe_wrap').Pipe; |
|
|
|
const { isUint8Array } = process.binding('util'); |
|
|
|
const child_process = require('internal/child_process'); |
|
|
|
|
|
|
|
const errnoException = util._errnoException; |
|
|
|
const _validateStdio = child_process._validateStdio; |
|
|
|
const setupChannel = child_process.setupChannel; |
|
|
|
const ChildProcess = exports.ChildProcess = child_process.ChildProcess; |
|
|
@ -508,8 +506,6 @@ function spawnSync(/*file, args, options*/) { |
|
|
|
|
|
|
|
var options = opts.options; |
|
|
|
|
|
|
|
var i; |
|
|
|
|
|
|
|
debug('spawnSync', opts.args, options); |
|
|
|
|
|
|
|
// Validate the timeout, if present.
|
|
|
@ -533,7 +529,7 @@ function spawnSync(/*file, args, options*/) { |
|
|
|
} |
|
|
|
|
|
|
|
// We may want to pass data in on any given fd, ensure it is a valid buffer
|
|
|
|
for (i = 0; i < options.stdio.length; i++) { |
|
|
|
for (var i = 0; i < options.stdio.length; i++) { |
|
|
|
var input = options.stdio[i] && options.stdio[i].input; |
|
|
|
if (input != null) { |
|
|
|
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]); |
|
|
@ -549,50 +545,27 @@ function spawnSync(/*file, args, options*/) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var result = spawn_sync.spawn(options); |
|
|
|
|
|
|
|
if (result.output && options.encoding && options.encoding !== 'buffer') { |
|
|
|
for (i = 0; i < result.output.length; i++) { |
|
|
|
if (!result.output[i]) |
|
|
|
continue; |
|
|
|
result.output[i] = result.output[i].toString(options.encoding); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.stdout = result.output && result.output[1]; |
|
|
|
result.stderr = result.output && result.output[2]; |
|
|
|
|
|
|
|
if (result.error) { |
|
|
|
result.error = errnoException(result.error, 'spawnSync ' + opts.file); |
|
|
|
result.error.path = opts.file; |
|
|
|
result.error.spawnargs = opts.args.slice(1); |
|
|
|
} |
|
|
|
|
|
|
|
util._extend(result, opts); |
|
|
|
|
|
|
|
return result; |
|
|
|
return child_process.spawnSync(opts); |
|
|
|
} |
|
|
|
exports.spawnSync = spawnSync; |
|
|
|
|
|
|
|
|
|
|
|
function checkExecSyncError(ret) { |
|
|
|
if (ret.error || ret.status !== 0) { |
|
|
|
var err = ret.error; |
|
|
|
ret.error = null; |
|
|
|
|
|
|
|
if (!err) { |
|
|
|
var msg = 'Command failed: '; |
|
|
|
msg += ret.cmd || ret.args.join(' '); |
|
|
|
if (ret.stderr && ret.stderr.length > 0) |
|
|
|
msg += '\n' + ret.stderr.toString(); |
|
|
|
err = new Error(msg); |
|
|
|
} |
|
|
|
|
|
|
|
util._extend(err, ret); |
|
|
|
return err; |
|
|
|
function checkExecSyncError(ret, args, cmd) { |
|
|
|
var err; |
|
|
|
if (ret.error) { |
|
|
|
err = ret.error; |
|
|
|
} else if (ret.status !== 0) { |
|
|
|
var msg = 'Command failed: '; |
|
|
|
msg += cmd || args.join(' '); |
|
|
|
if (ret.stderr && ret.stderr.length > 0) |
|
|
|
msg += '\n' + ret.stderr.toString(); |
|
|
|
err = new Error(msg); |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
if (err) { |
|
|
|
err.status = ret.status < 0 ? uv.errname(ret.status) : ret.status; |
|
|
|
err.signal = ret.signal; |
|
|
|
} |
|
|
|
return err; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -605,7 +578,7 @@ function execFileSync(/*command, args, options*/) { |
|
|
|
if (inheritStderr && ret.stderr) |
|
|
|
process.stderr.write(ret.stderr); |
|
|
|
|
|
|
|
var err = checkExecSyncError(ret); |
|
|
|
var err = checkExecSyncError(ret, opts.args, undefined); |
|
|
|
|
|
|
|
if (err) |
|
|
|
throw err; |
|
|
@ -620,12 +593,11 @@ function execSync(command /*, options*/) { |
|
|
|
var inheritStderr = !opts.options.stdio; |
|
|
|
|
|
|
|
var ret = spawnSync(opts.file, opts.options); |
|
|
|
ret.cmd = command; |
|
|
|
|
|
|
|
if (inheritStderr && ret.stderr) |
|
|
|
process.stderr.write(ret.stderr); |
|
|
|
|
|
|
|
var err = checkExecSyncError(ret); |
|
|
|
var err = checkExecSyncError(ret, opts.args, command); |
|
|
|
|
|
|
|
if (err) |
|
|
|
throw err; |
|
|
|