![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Write-Output is bleeding into a pipe why On Sep 25, 11:32 am, Bob Landau <BobLan...@xxxxxx> wrote: Quote: > 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 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 |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Write-Output is bleeding into a pipe why On Sep 25, 3:36 am, Jeff <jeff.hill...@xxxxxx> wrote: Quote: > On Sep 25, 11:32 am, Bob Landau <BobLan...@xxxxxx> > wrote: > > > > > Quote: > > 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. Quote: > > Can anyone explain to me whether its me or PS? Quote: > > thx > > bob > > ============== > > function Parse_Arguments( [object[]] $myargs ) > > { Quote: > > echo "in $($MyInvocation.MyCommand.name)" > > $i=0 > > foreach ($arg in $myargs) {echo "`$args[$i] = $($arg)"; $i++} Quote: > > $Param = $myargs | > > foreach { > > switch ($_) > > { > > 1 { $e = @{}; $e.a = 1; $e} > > } > > } Quote: > > echo "`$Param.count is $($Param.Count)" Quote: > > foreach ($p in $Param) { echo "`$p is $($p['a'])" } Quote: > > echo "leaving $($MyInvocation.MyCommand.name)" > > $Param Quote: > > } Quote: > > $Params = Parse_Arguments $args Quote: > > ## Unless the below statement is uncommented the "echo" statements above > > never are written to screen > > ## $Params Quote: > > 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() Quote: > > switch ($p.a) > > { > > 1 { echo "1" } Quote: > > Default {echo "Why is the output of `"echo`" being piped into > > here?: $([int][char]$_)"} > > } > > } Quote: > > To duplicate this write this out as t.ps1 and invoke it as .\t.ps1 1 > If you look at the help for Write-Output (Get-Help Write-Output), you > 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- Hide quoted text - > > - Show quoted text - to be aliased to write-host, not write-output like it is now? that surprised me. - Oisin |
My System Specs![]() |
| | #4 (permalink) |
| | 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: Quote: > On Sep 25, 3:36 am, Jeff <jeff.hill...@xxxxxx> wrote: Quote: > > On Sep 25, 11:32 am, Bob Landau <BobLan...@xxxxxx> > > wrote: > > > > > > > > > > Quote: > > > 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. Quote: > > > Can anyone explain to me whether its me or PS? Quote: > > > thx > > > bob > > > ============== > > > function Parse_Arguments( [object[]] $myargs ) > > > { Quote: > > > echo "in $($MyInvocation.MyCommand.name)" > > > $i=0 > > > foreach ($arg in $myargs) {echo "`$args[$i] = $($arg)"; $i++} Quote: > > > $Param = $myargs | > > > foreach { > > > switch ($_) > > > { > > > 1 { $e = @{}; $e.a = 1; $e} > > > } > > > } Quote: > > > echo "`$Param.count is $($Param.Count)" Quote: > > > foreach ($p in $Param) { echo "`$p is $($p['a'])" } Quote: > > > echo "leaving $($MyInvocation.MyCommand.name)" > > > $Param Quote: > > > } Quote: > > > $Params = Parse_Arguments $args Quote: > > > ## Unless the below statement is uncommented the "echo" statements above > > > never are written to screen > > > ## $Params Quote: > > > 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() Quote: > > > switch ($p.a) > > > { > > > 1 { echo "1" } Quote: > > > Default {echo "Why is the output of `"echo`" being piped into > > > here?: $([int][char]$_)"} > > > } > > > } Quote: > > > To duplicate this write this out as t.ps1 and invoke it as .\t.ps1 1 > > If you look at the help for Write-Output (Get-Help Write-Output), you > > 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- Hide quoted text - > > > > - Show quoted text - > ....and on that note, is it just me, or did anyone else expect "echo" > to be aliased to write-host, not write-output like it is now? that > surprised me. > > - Oisin > > > |
My System Specs![]() |
| | #5 (permalink) |
| | 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: Quote: > On Sep 25, 11:32 am, Bob Landau <BobLan...@xxxxxx> > wrote: Quote: > > 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 > If you look at the help for Write-Output (Get-Help Write-Output), you > 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 > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Write-Output is bleeding into a pipe why "Bob Landau" <BobLandau@xxxxxx> wrote in message news 39C1D3D-4538-42D6-BFE8-AD321C6E3AD1@xxxxxxQuote: > 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? PowerShell Item 7: Understanding "Output"'. Perhaps you will find it useful: http://keithhill.spaces.live.com/blo...3A97!811.entry -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Send command line via WMI - Pipe output to text file on remote mac | PowerShell | |||
| Re: Send command line via WMI - Pipe output to text file on remote | PowerShell | |||
| Write-Output sends $null down the pipe | PowerShell | |||
| No output from write-output | PowerShell | |||
| write-output array without C/R | PowerShell | |||