PowerShell and Tee
-
My-Command 2>&1 | Tee-Object 'myfile.log'
. SeeGet-Help about_Redirection
. - You should be trapping errors, not relying on Ctrl+C. See
Get-Help about_Try_Catch_Finally
. Is the command you're running an external program or a script? - As I understand it, typically string objects are not sent down the pipe until an end-of-line character is reached. The reason is quite simple: if it didn't do this, partial (read: incomplete) strings would go down the pipe.
Tee
might handle partial strings fine, but other cmdlets likeForEach-Object
orSelect-Object
certainly would not. Note thatGet-Content
has a special switch-ReadCount
which somewhat overrides this behavior, and it will seriously mess with aSelect-Object -Skip/-First/-Last/-Unique
command further down the pipe.
It very well may be that external programs you're running aren't going to obey the conventions that PowerShell is expecting. Tee
, for example, is properly called Tee-Object
, which should tell you the kinds of things it's good at working with. In that case, you may be further along the line to get tee.exe
from GNU Win32 Utils or MSYS which are designed for immediately forwarding content.