【发布时间】:2013-05-29 03:51:01
【问题描述】:
我正在尝试在下一个代码中运行子进程:
run = function (cmd, callback) {
var spawn = require('child_process').spawn;
var command = spawn(cmd);
var result = '';
command.stdout.on('data', function (data) {
result += data.toString();
});
command.on('exit', function () {
callback(result);
});
}
execQuery = function (cmd) {
var result = {
errnum: 0,
error: 'No errors.',
body: ''
};
run(cmd, function (message) {
result.body = message;
console.log(message);
});
return result;
}
执行后 execQuery('ls') result.body 始终为空,但 console.log 是包含值。
【问题讨论】:
标签: node.js variables process stdout output