将git命令记录到Powershell成绩单中的奇怪区别 [英] Odd differences in logging git commands to a Powershell Transcript
问题描述
请参阅此问题,以了解我想了解的行为.
See this question for the full context of the behavior I'm trying to understand.
我对 Start-Transcript
的理解是,一旦启动,所有输出流都将记录到Powershell脚本中.我可以写到流1-6,但仍然希望在笔录中看到输出.但是,在我上面链接的问题中,我看到了一些我无法解释的奇怪现象,并且想了解为什么在这种情况下会吞噬输出,并且在这种情况下,我们每个人都看到了不同的行为.
My understanding of Start-Transcript
is that all output streams are logged to the Powershell transcript once it is started. I can write to streams 1-6 and still expect to see the output in my transcript log. However, in the question I linked to above, I'm seeing some strangeness surrounding this I can't explain and would like to understand why the output is swallowed in this case, and in that OP's case, we were each seeing different behavior.
基本上,OP尝试记录 git clone |Out-Default
记录到他们的笔录中,但没有任何内容注销到笔录中.对他们有效的解决方案是设置一个环境变量,使 git
写入 stdout
而不是 stderr
.OP后来表示,他们曾尝试将 git
命令传递给 Out-Default
,以查看是否有所作为,但没有,因此,他们的解决方案似乎是" git
输出到stderr,并且不会被 Start-Transcript
捕获.
Basically, OP was trying to log git clone | Out-Default
to their transcript log, and was getting nothing logged out to the transcript. The solution that worked for them was to set an environment variable to have git
write to stdout
instead of stderr
. OP later stated that they had tried piping the git
command to Out-Default
to see if it made a difference, which it did not, so they're solution seems to be that "git
outputs to stderr and does not get captured by Start-Transcript
.
但是,我的经历有所不同.我没有配置 git
来将 stderr
重定向到 stdout
,并且可以通过尝试将git命令的输出分配给变量来确认这一点.(如我所料,这是行不通的).但是,我可以简单地调用 Start-Transcript
,然后调用 git status
,然后查看它是否记录在笔录中.但是,当我运行 git status |超出默认值
,我将输出输出到控制台,但未记录到成绩单.删除 Out-Default
似乎是我的解决方案,但不是OP的解决方案.
My experience differed, however. I do not have git
configured to redirect stderr
to stdout
, and can confirm this by attempting to assign the output of a git command to a variable (which doesn't work, as I expected). Yet I can simply call Start-Transcript
, then call git status
, and see that it logs to the transcript. However, when I run git status | Out-Default
, I get the output to the console, but not logged to the transcript. Removing Out-Default
seemed to be the solution for me, but not for OP.
我不知所措.在我的系统上,似乎将 git
命令和仅 git
命令传递给 Out-Default
不允许将输出记录到成绩单.我已经用它们的 stderr
输出测试了其他外部程序,并将输出通过管道传输到 Out-Default
仍然允许输出被转录.但不是 git blah |超默认值
.而且我仍然不明白为什么另一个问题的OP需要将 stderr
重定向到 stdout
,但是我不需要.
I'm at a loss as to what is going on here. On my system it seems that piping git
commands, and only git
commands, to Out-Default
does not allow the output to be logged to a transcript. I've tested other external programs with their stderr
output and piping the output to Out-Default
still allows the output to be transcribed. But not git blah | Out-Default
. And I still don't understand why the other question's OP needed to redirect stderr
to stdout
, but I don't.
推荐答案
您看到的 bug 在以下情况下会浮出水面:
You're seeing a bug that surfaces under the following condition:
-
转录(以
Start-Transcript
开头)正在进行
一个外部程序(例如 git
)被调用,并且它还将(也)输出到 stderr (标准错误流).
an external program (such as git
) is being called, and it outputs (also) to stderr (the standard error stream).
外部程序调用通过管道传递到 Out-Default
.
the external-program call is piped to Out-Default
.
然后,stderr输出意外地未记录在成绩单中. [1]
The stderr output is then unexpectedly not recorded in the transcript.[1]
已在此GitHub问题中报告了该问题,但请务必注意
The problem has been reported in this GitHub issue, but it's important to note that:
-
在这种情况下,没有没有理由调用
Out-Default
,因为默认情况下,脚本会记录外部程序的stdout和stderr输出.
There's no reason to call
Out-Default
in this scenario, because the transcript by default records both stdout and stderr output from external programs.
通常 没有理由从用户代码中调用 Out-Default
;它旨在由PowerShell主机应用程序调用.
There's generally no reason to call Out-Default
from user code; it is designed to be called by PowerShell host applications.
有关更多信息,请参见此答案.
See this answer for more information.
[1]请注意,通常将外部程序的stderr输出与PowerShell命令的错误输出区别对待:除非重定向,否则默认情况下,stderr行将显示在显示屏上,而不会触及PowerShell的错误流(因此也不会记录在 $ Error
中),因为通常不能假定stderr表示错误,因为许多程序(包括 git
)都使用它来编写状态信息.
[1] Note that stderr output from external programs is generally treated differently than error output from PowerShell commands: unless redirected, stderr lines are printed to the display by default, without touching PowerShell's error stream (and therefore also without being recorded in $Error
), because stderr cannot generally be assumed to represent errors, given that many programs - including git
- use it to write status information too.
这篇关于将git命令记录到Powershell成绩单中的奇怪区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!