PowerShell Capture Git Output

后端 未结 1 1055
面向向阳花
面向向阳花 2020-12-03 23:33

Problem

I am running some git commands through PowerShell but I am having issues capturing the output.

Many of the ways I have looked into have failed to c

相关标签:
1条回答
  • 2020-12-04 00:17

    As I explained here, or here, Git command output are done on stderr, not stdout.

    So in your case, you need to pipe stderr.
    See "Redirection of standard and error output appending to the same log-file" for instance.

    Note: with Git 2.16 (Q1 2018), you can try and set first

     set GIT_REDIRECT_STDERR=2>&1
    

    Then stderr should be redirected to stdout.

    In "PowerShell - Capturing STDERR Output for Git Commands", the OP Brandon points out to the --porcelain option of (for instance) git push:

    & git status --porcelain >> $logFilePath
    & git push --porcelain >> $logFilePath
    

    It allows to convert the outputs into a machine readable format and pipe them to the output.

    0 讨论(0)
提交回复
热议问题