The following powershell command works as expected:

get-process | tee-object -filepath C:\Test1\testfile2.txt

But if I change it to:

git pull | tee-object -filepath C:\Test1\testfile2.txt

I see the git pull command execute normally but C:\Test1\testfile2.txt still has the output from get-process.

Any idea why?

  • git pull |gm .................... – Jaqueline Vanek May 15 '17 at 22:34
  • gm Enumerate the properties of an object ? – Eric May 16 '17 at 15:08
  • I see: gm : You must specify an object for the Get-Member cmdlet. At line:1 char:12 + git pull | gm + ~~ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand – Eric May 16 '17 at 16:43
  • git isn't a cmdlet and so doesn't expose objects to the pipeline. Normal output from .exe programs to standardout should be piped and handled properly by Tee-Object. Maybe git output is to stderror, so try git pull 2>&1 | tee-object -filepath C:\Test1\testfile2.txt – LotPings May 16 '17 at 18:22
  • That worked, can you explain what the 2>&1 part does? – Eric May 16 '17 at 18:34
  • In cmd.exe there are two output streams, stdoutput and stderroroutput numbered 1 and 2.
  • Batch/console prepends 1 to a redirection > if not a different stream number is supplied manually.
  • Looks like git outputs to stderroroutput, so 2>&1 merges stderroroutput(2) with stdoutput(1) so it is piped and tee is able to echo and store to the file.
  • In powershell there are additional streams, see powershell streams

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.