Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stdout is empty on Git log command #439

Closed
oric01 opened this issue May 3, 2016 · 8 comments
Closed

Stdout is empty on Git log command #439

oric01 opened this issue May 3, 2016 · 8 comments

Comments

@oric01
Copy link

oric01 commented May 3, 2016

  • node 4.4.0
  • shelljs 0.7.0
  • windows 7, using git bash

Using shelljs to stdout Git log does not work (in grunt file currently).

var shell = require('shelljs');
console.log(shell.exec('node -v'));

Works, console stdout : stdout: 'v4.4.0\r\n'

console.log(shell.exec('git log --no-merges --pretty=medium HEAD^...HEAD'));

Does not works, Works, console stdout : stdout: ''

While this Git log works in Git bash :

$ git log --no-merges --pretty=medium HEAD^...HEAD
commit be9a8bca6783f9911f0601afa00203f9a161ffd9
Author: xxx <xxx.xxx@xxx>
Date:   Tue Apr 26 17:02:47 2016 +0200

    feat(streaming): XXX : XXX

    - change 1
    - change 1

@nfischer
Copy link
Member

nfischer commented May 3, 2016

@oric01 do other git commands (like git status) work? Also, what is the output on the terminal when you redirect stdout?

$ git log --no-merges --pretty=medium HEAD^...HEAD >file.txt

Just want to verify that the git log command really is going to stdout for you and not stderr.

@oric01
Copy link
Author

oric01 commented May 4, 2016

@nfischer It's strange... now when i run shelljs, git command is unknown... while it's still running on git bash.
I'm a bit confused, it was at least running git command correctly until now.
FYI, I installed git bash the way it's not available in cmd.exe, but as far as I understand, it should'nt be a problem.

Previously the returned code was 0 with just stdout empty (on git log) and I also finally noticed that shelljs was running cmd.exe so I was waiting for #330 to be fixed, but my problem still remain.

@nfischer
Copy link
Member

nfischer commented May 4, 2016

It has to be part of your path to use it. Exec spawns a new cmd.exe. Please add the git binaries to your path first to take advantage of them via shelljs.

@oric01
Copy link
Author

oric01 commented May 4, 2016

Is there a way that shelljs use bash instead of cmd.exe ?
Currently im using git bash to have a "unix like" shell so I can run the same scripts between local env (window) and dist env (linux) for grunt build scripts ie.

@nfischer
Copy link
Member

nfischer commented May 4, 2016

Yes, you need to use the {'shell': '/path/to-bash.exe'} argument to exec. That may work nicely for you. Find whatever the path is to your bash executable of course and past that in there, remembering to properly escape any backslashes and whatnot.

@nfischer
Copy link
Member

nfischer commented May 4, 2016

@oric01 Here's the exec docs, which point to the page for the child_process module. Any option in that module's exec should be supported here as well, including shell.

@nfischer
Copy link
Member

nfischer commented May 7, 2016

@oric01 I'm going to close this, since it looks like it was an issue with git being outside of your normal PATH, and that using {shell: 'path/to/git/bash.exe'} should fix it. Please reopen if this doesn't resolve the issue.

@nfischer nfischer closed this as completed May 7, 2016
@oric01
Copy link
Author

oric01 commented May 9, 2016

I tested with shell option but it's a pain to configure on windows...
I finally tested git status and it works...
Looks like it's related to the way git log is not flushed.
I continue to investigate...anyway thx for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants