See 这个问题 https://stackoverflow.com/questions/58942723/powershell-transcript-is-not-capturing-git-output/58943306了解我试图理解的行为的完整背景。
我的理解Start-Transcript
是一旦启动,所有输出流都会记录到 Powershell 转录本中。我可以写入流 1-6,并且仍然希望在我的转录日志中看到输出。然而,在我上面链接的问题中,我看到了一些围绕这个的奇怪现象,我无法解释,并且想了解为什么在这种情况下输出被吞没,而在那个OP的情况下,我们每个人都看到了不同的行为。
基本上,OP 试图记录git clone | Out-Default
到他们的成绩单日志中,并且没有将任何内容记录到成绩单中。对他们有用的解决方案是设置一个环境变量git
写给stdout
代替stderr
。 OP 后来表示,他们曾尝试用管道输送git
命令到Out-Default
看看它是否有所作为,但事实并非如此,所以他们的解决方案似乎是“git
输出到 stderr 并且不会被捕获Start-Transcript
.
然而,我的经历有所不同。我没有git
配置为重定向stderr
to stdout
,并且可以通过尝试将 git 命令的输出分配给变量来确认这一点(正如我所期望的那样,这不起作用)。但我可以简单地打电话Start-Transcript
,然后调用git status
,并查看它是否记录到记录中。然而,当我跑步时git status | Out-Default
,我将输出发送到控制台,但未记录到记录中。去除Out-Default
对我来说似乎是解决方案,但对OP来说不是。
我不知道这里发生了什么。在我的系统上,管道似乎git
命令,并且仅git
命令,至Out-Default
不允许将输出记录到记录中。我已经用它们测试了其他外部程序stderr
输出并将输出通过管道传输到Out-Default
仍然允许转录输出。但不是git blah | Out-Default
。我仍然不明白为什么另一个问题的OP需要重定向stderr
to stdout
,但我没有。
你正在看到一个bug在以下条件下表面:
转录(以Start-Transcript
) 正在进行
an 外部程序(例如git
) 被调用,并且它(也)输出到stderr(标准错误流)。
外部程序调用通过管道传送到Out-Default
.
The stderr output is then unexpectedly not recorded in the transcript.[1]
该问题已报告于这个 GitHub 问题 https://github.com/PowerShell/PowerShell/issues/11134,但值得注意的是:
See 这个答案 https://stackoverflow.com/a/58958346/45375了解更多信息。
[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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)