当试图运行git shortlog和nodejs时,Exec不会返回任何东西 [英] Exec not returning anything when trying to run git shortlog with nodejs

查看:137
本文介绍了当试图运行git shortlog和nodejs时,Exec不会返回任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



<$ p

我试图通过nodejs获取 git shortlog 的结果:

$ p> var exec = require('child_process')。exec;
exec(cd / tmp /+ folder +&& git shortlog,{maxBuffer:500 * 1024},function(error,stdout,stderror){
console.log(arguments );
});

我的回调函数永远不会用这个方法调用,程序会无限期地处理某些东西。 b
$ b

在我的提示符中启动此命令时,我得到了结果。



尝试将结果重定向到文件,创建一个空file:

 cd / tmp /+文件夹+&&& git shortlog> stats.txt

但是如果我使用 git log 得到我的结果。



你知道为什么我的回调永远不会被调用 git shortlog



编辑:
我使用spawn获得了相同的结果:

  exec ('cd / tmp /'+文件夹,函数(err){
if(err){
throw err;
}

var shortlog = spawn(' git',['shortlog']);
shortlog.stdout.on('data',function(data){
console.log('stdout:'+ data);
} );

shortlog.stderr.on('data',functi on(data){
console.log('stderr:'+ data);
});
$ b shortlog.on('close',function(code){
console.log('child process exited with code'+ code);
});
});

编辑2:
process.chdir()不会改变任何内容:

  process.chdir('/ tmp /'+ folder); 
var shortlog = spawn('git',['shortlog']);
shortlog.stdout.on('data',function(data){
console.log('stdout:'+ data);
});


解决方案

git shortlog 认为它必须从stdin中读取一些东西,因此无限期等待。试试这个:

  exec('git shortlog< / dev / tty',{cwd:/ tmp /+文件夹},函数(err,stdout,stderr){
console.log(arguments);
});


I'm trying to get the result of git shortlog on a repository with nodejs this way:

var exec = require('child_process').exec;
exec("cd /tmp/"+folder +" && git shortlog", {maxBuffer: 500*1024}, function(error, stdout, stderror){
    console.log(arguments);
});

My callback is never called with this method, the program appears processing something indefinitely.

When I launch this command in my prompt I've the results.

Trying to redirect the result to a file create an empty file :

"cd /tmp/"+folder +" && git shortlog > stats.txt"

But if I use git log instead I've got my results.

Do you know why my callback is never called with git shortlog ?

Edit : I've the same result using spawn :

exec("cd /tmp/"+folder, function(err){
    if(err){
        throw err;
    }

    var shortlog = spawn('git', ['shortlog']);
    shortlog.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });

    shortlog.stderr.on('data', function (data) {
        console.log('stderr: ' + data);
    });

    shortlog.on('close', function (code) {
        console.log('child process exited with code ' + code);
    });
});

Edit 2 : process.chdir() doesn't change anything :

process.chdir('/tmp/'+folder);
var shortlog = spawn('git', ['shortlog']);
shortlog.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
});

解决方案

git shortlog thinks that it has to read something from stdin, hence the indefinite wait. Try this:

exec('git shortlog < /dev/tty', { cwd : "/tmp/" + folder }, function(err, stdout, stderr) {
  console.log(arguments);
});

这篇关于当试图运行git shortlog和nodejs时,Exec不会返回任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆