我想在节点js代码中执行以下命令
diff <(git log 01) <(git log 02)
在命令行中,它正在正常工作,我想要gettig所需的输出
这是我的节点代码
var command = "diff <(git log 01) <(git log 02)"
console.log(command)
exec(command, function (error, stdout, stderr) {
if (error !== null) {
console.log(error)
} else {
console.log(stdout)
}
}
});
但是在执行上面的代码时越来越
diff <(git 01) <(git log 02)
{ [Error: Command failed: /bin/sh: 1: Syntax error: "(" unexpected
] killed: false, code: 2, signal: null }
尝试像这样运行它:
var spawn = require('child_process').spawn;
var command = "diff <(git log 01) <(git log 02)";
console.log(command)
var diff = spawn('bash', ['-c', command]);
diff.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
diff.stderr.on('data', function (data) {
console.error('stderr: ' + data);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句