3

See this question for the full context of the behavior I'm trying to understand.

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.

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.

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.

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.

codewario
  • 19,553
  • 20
  • 90
  • 159

1 Answers1

2

You're seeing a bug that surfaces under the following condition:

  • a transcription (started with Start-Transcript) is ongoing

  • an external program (such as git) is being called, and it outputs (also) to stderr (the standard error stream).

  • the external-program call is piped to Out-Default.

The stderr output is then unexpectedly not recorded in the transcript.[1]

The problem has been reported in this GitHub issue, but it's important to note that:

  • 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.

  • 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] 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.

mklement0
  • 382,024
  • 64
  • 607
  • 775