Try using spawn instead of exec so you can inherit the stdio.
'use strict';
var spawn = require('child_process').spawn;
var commit = spawn('git', ['commit'], {stdio : 'inherit'});
题
I'd like to run a command from Node like git commit
. I can do that by doing:
var exec = require("child_process").exec;
exec("git commit", function(error, stderr, stdout) {
// Do stuff
});
However, it always hangs. I assume this is because git commit
wants to take control of the console to open vim/emacs or whatever, but Node isn't allowing it. Is there a way to fix this?
解决方案
Try using spawn instead of exec so you can inherit the stdio.
'use strict';
var spawn = require('child_process').spawn;
var commit = spawn('git', ['commit'], {stdio : 'inherit'});