yep keith alludes to something important
many times people are wanting to capture all that came on the screen.
and they do something like
1..5 | % { write-host "this screen $_" ; "in pipe $_" } > myfile.txt
and under other shells all the output include the stuff from write-host
would be redirected to myfile.txt
however in powershell this is not the case, which people say is stupid,
but here is the reason.
Quote:
> isn't really file redirection as you previously know it , it
effectively is just puting to out-file
and out-file is taking the input from the PIPELINE and then outputting
it.. thus what was written directly to the screen gets lost..
this can be hard, but you see in powershell, everything (other than
native calls) is running inside the same process.. STDIO redirection
happens between process boundaries , and thus wouldn't pick up all the
stuff happening in a IN MEMORY/ IN PROCESS powershell pipeline.
there are ways to do it.. i.e call an external powershell process, in
that case its running another process, and the STDOUT of that external
powershell call is directed back into your calling powershell with all
the results as text
powershell { 1..5 | % { write-host "this screen $_" ; "in pipe $_" } }