Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modify spawn to still return (err, stdout, stderr).

  • Loading branch information...
commit a959e2f22e94c414cfff4e198cc080a2730e2e62 1 parent c69f49a
@Kami Kami authored
Showing with 13 additions and 17 deletions.
  1. +3 −4 lib/util/knife.js
  2. +10 −13 lib/util/misc.js
View
7 lib/util/knife.js
@@ -22,18 +22,17 @@ function knife(args, options) {
args = ['/usr/bin/knife'].concat(args);
- misc.spawn(args, {env: env}, function(err, result) {
- var payload, data;
+ misc.spawn(args, {env: env}, function(err, stdout, stderr) {
+ var payload;
if (err) {
callback(err);
return;
}
- data = result.stdout;
if (args.indexOf('json') >= 0) {
try {
- payload = JSON.parse(data);
+ payload = JSON.parse(stdout);
} catch (e) {
callback(e);
return;
View
23 lib/util/misc.js
@@ -18,17 +18,17 @@ exports.getUnixTimestamp = function getDateTimestamp(date) {
/** Spawn a subprocess and issue the callback.
* @param {Array} cmd Command and Arguments.
* @param {Options} spawnOpts Options object passed to the spawn command.
- * @param {Function} callback Completion callback(err, resultObj).
+ * @param {Function} callback Completion callback(err, stdout, stderr).
*/
exports.spawn = function(cmd, spawnOpts, callback) {
var args,
startTime,
endTime,
+ diff,
proc,
resultString = '',
errString = '',
- cmdStr,
- resultObj = {};
+ cmdStr;
// Copy command so we don't override the parent
cmd = cmd.slice();
@@ -48,19 +48,16 @@ exports.spawn = function(cmd, spawnOpts, callback) {
proc.on('exit', function(code) {
var err;
endTime = getUnixTimestamp();
- resultObj.stdout = resultString;
- resultObj.stderr = errString;
- result.time = (endTime - startTime);
-
+ diff = (endTime - startTime);
if (code) {
err = new Error(sprintf('Failed command %s:\nstderr:\n%s\nstdout:\n%s', cmdStr, errString, resultString));
}
log.info('Command %s finished', {cmd: cmdStr, err: err, start_time: startTime,
- end_time: endTime, took: result.time});
+ end_time: endTime, took: diff});
- callback(err, resultObj);
+ callback(err, resultString, errString);
});
};
@@ -88,16 +85,16 @@ exports.taskSpawn = function(baton, args, cmd, options, callback) {
cmd: cmdStr
});
- exports.spawn(cmd, options, function(err, result) {
+ exports.spawn(cmd, options, function(err, stdout, stderr) {
if (err) {
baton.log.errorf('error executing command: ${cmd}', {
cmd: cmdStr,
err: err,
- stdout: result.stdout,
- stderr: result.stderr
+ stdout: stdout,
+ stderr: stderr
});
}
- callback(err, result.stdout, result.stderr);
+ callback(err, stdout, stderr);
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.