child_process exec && spawn just hang

1,627 views
Skip to first unread message

alessioalex

unread,
May 14, 2013, 9:46:59 AM5/14/13
to nod...@googlegroups.com
Hey,

I'm trying to get the list of the authors of a git project using 'git shortlog -sne' using child process, but it seems that both exec and spawn just hang. The command works ok in the terminal, so it's really weird. Here's my snippet:


var child_process = require('child_process'),                                                     
    exec  = child_process.exec,                                                                   
    spawn = child_process.spawn;                                                                  
                                                                                                  
var child = spawn('git', ['--git-dir=/home/alessio/www/git-project/.git', 'shortlog']);                 
child.stdout.on('data', function(data) {                                                          
  console.log('stdout: ' + data);                                                                 
});                                                                                               
child.on('close', function(code) {                                                                
  console.log('child process exited with code ' + code);                                          
});                                                                                               
child.stderr.on('data', function(data) {                                                          
  console.log('stderr: ' + data);                                                                 
});                                                                                               
                                                                                                  
exec('git --git-dir=/home/alessio/www/git-project/.git shortlog -sne', function(err, stdout, stderr) {  
  console.log(arguments);                                                                         
});



Any suggestions?

Thanks,
Alex

Jorge

unread,
May 14, 2013, 10:10:59 AM5/14/13
to nod...@googlegroups.com
var repo= "/home/alessio/www/git-project/";
require('child_process').exec('cd \''+repo+'\' ; git log', console.log);

--
( Jorge )();

alessioalex

unread,
May 14, 2013, 10:18:56 AM5/14/13
to nod...@googlegroups.com
Hey Jorge,

The problem is that other commands work, event 'git shortlog' (when I add the '--help' arg or another invalid argument). My problem is with 'git --git-dir=/path/to/project/.git shortlog'. That specific command hangs when using exec or spawn :(

Thanks

Jorge

unread,
May 14, 2013, 10:39:16 AM5/14/13
to nod...@googlegroups.com
On 14/05/2013, at 16:18, alessioalex wrote:

> Hey Jorge,
>
> The problem is that other commands work, event 'git shortlog' (when I add the '--help' arg or another invalid argument). My problem is with 'git --git-dir=/path/to/project/.git shortlog'. That specific command hangs when using exec or spawn :(

Yes I know, handling of params is a bit tricky and has always been... but this works fine:

var repo= "/home/alessio/www/git-project/";
require('child_process').exec('cd \''+repo+'\' ; git shortlog -sne', console.log);

So I would just use what works :-)
--
( Jorge )();

alessioalex

unread,
May 14, 2013, 11:01:50 AM5/14/13
to nod...@googlegroups.com
Hey Jorge, I just tried that and it still hangs :( Note that for whatever git command except shortlog everything works fine. Thanks for trying to help.

mscdex

unread,
May 14, 2013, 11:54:56 AM5/14/13
to nodejs
On May 14, 9:46 am, alessioalex <alessio.ijoo...@gmail.com> wrote:
> I'm trying to get the list of the authors of a git project using 'git
> shortlog -sne' using child process, but it seems that both exec and spawn
> just hang. The command works ok in the terminal, so it's really weird.

http://stackoverflow.com/questions/15564185/exec-not-returning-anything-when-trying-to-run-git-shortlog-with-nodejs

Jorge

unread,
May 14, 2013, 1:24:46 PM5/14/13
to nod...@googlegroups.com
On 14/05/2013, at 17:01, alessioalex wrote:

> Hey Jorge, I just tried that and it still hangs :(

ORLY? Then I have no idea... ;-P

Cheers,
--
( Jorge )();

alessioalex

unread,
May 14, 2013, 1:48:20 PM5/14/13
to nod...@googlegroups.com
@mscdex thanks a lot man, I owe you
Reply all
Reply to author
Forward
0 new messages