![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest
Posts: n/a
| Write-Output is bleeding into a pipe why Below is a greatly simplified example of what I'm experiencing. Each time Write-Output is being called it is being piped into my array. Can anyone explain to me whether its me or PS? thx bob ============== function Parse_Arguments( [object[]] $myargs ) { echo "in $($MyInvocation.MyCommand.name)" $i=0 foreach ($arg in $myargs) {echo "`$args[$i] = $($arg)"; $i++} $Param = $myargs | foreach { switch ($_) { 1 { $e = @{}; $e.a = 1; $e} } } echo "`$Param.count is $($Param.Count)" foreach ($p in $Param) { echo "`$p is $($p['a'])" } echo "leaving $($MyInvocation.MyCommand.name)" $Param } $Params = Parse_Arguments $args ## Unless the below statement is uncommented the "echo" statements above never are written to screen ## $Params foreach ($p in $Params) { ## Uncomment the below statement to see what the output of Param[0] - Param[4] is ## For some reason Write-Output is being piped into Param $host.EnterNestedPrompt() switch ($p.a) { 1 { echo "1" } Default {echo "Why is the output of `"echo`" being piped into here?: $([int][char]$_)"} } } To duplicate this write this out as t.ps1 and invoke it as .\t.ps1 1 |
| | #2 (permalink) | ||||||||||||
| Guest
Posts: n/a
| Re: Write-Output is bleeding into a pipe why On Sep 25, 11:32 am, Bob Landau <BobLan...@xxxxxx> wrote:
will see that its purpose is to write objects to the pipeline. Anything in a function that isn't consumed by something else becomes an output, which is why your Write-Output calls are being combined with $Params. If you want something to go to the console, and not the pipeline, use Write-Host. Jeff | ||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Write-Output is bleeding into a pipe why On Sep 25, 3:36 am, Jeff <jeff.hill...@xxxxxx> wrote:
to be aliased to write-host, not write-output like it is now? that surprised me. - Oisin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Write-Output is bleeding into a pipe why I'm not sure about other OS's but "echo" has always written to stdout in Windows. However the behavior I'm seeing does surprise me. "Oisin Grehan" wrote:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Write-Output is bleeding into a pipe why Thank you Jeff for the explaination. It's not that I didn't read Write-* cmdlets as well as about_redirection; I did. Its just that NO place have I been able to find on the Web, PS official doc's or my trusty "PS in Action" that the Pipe Operator will gobble up _everything_ sent to Write-Output _within_ the entire function. Take a look below again; the pipe operator scope in my opinion should be piping only the output in the ForEach Scriptblock. I see no reason why it should be so greedy as to grab everything with the scope of the function. Does anyone else find this to be as unfriendly as I do? What I've ended up doing is write the function in a sub-expression and explictly pipe to Out-Host. Which basically does want you've mentioned although it does allow me to redirect to a file if I want bob "Jeff" wrote:
| ||||||||||||||||||||||||