![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Guest | No output from write-output I have this script, which does not run as I expected. ---------------------------------------- function foo($bar) { write-output "I got $bar" } foo "Hello" measure-command {foo "World"} --------------------------------------- Here is the ouput. --------------------------------------- I got Hello Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 1 Ticks : 15418 TotalDays : 1.78449074074074E-08 TotalHours : 4.28277777777778E-07 TotalMinutes : 2.56966666666667E-05 TotalSeconds : 0.0015418 TotalMilliseconds : 1.5418 -------------------------------------------------- Why didn't I get a line saying I got World Douglas Woods |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: No output from write-output > Why didn't I get a line saying > I got World Because write-output doesn't write to the console. It sends objects down the pipeline which measure-command will then discard. measure-object will only output the TimeSpan object for how long it took. write-host will write to the console. So if you change write-output to write-host you'll get what you expected. "DouglasWoods" <DouglasWoods@discussions.microsoft.com> wrote in message news E5409AF-3797-48C3-9462-7E80D105081E@microsoft.com...>I have this script, which does not run as I expected. > ---------------------------------------- > function foo($bar) > { > write-output "I got $bar" > } > > foo "Hello" > measure-command {foo "World"} > --------------------------------------- > > Here is the ouput. > > --------------------------------------- > I got Hello > > > Days : 0 > Hours : 0 > Minutes : 0 > Seconds : 0 > Milliseconds : 1 > Ticks : 15418 > TotalDays : 1.78449074074074E-08 > TotalHours : 4.28277777777778E-07 > TotalMinutes : 2.56966666666667E-05 > TotalSeconds : 0.0015418 > TotalMilliseconds : 1.5418 > -------------------------------------------------- > > Why didn't I get a line saying > I got World > > Douglas Woods |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: No output from write-output On Apr 10, 8:03 pm, "Marcel J. Ortiz [MSFT]" <mos...@online.microsoft.com> wrote: > > Why didn't I get a line saying > > I got World > > Because write-output doesn't write to the console. It sends objects down > the pipeline which measure-command will then discard. measure-object will > only output the TimeSpan object for how long it took. write-host will write > to the console. > So if you change write-output to write-host you'll get what you expected. In my opinion outputting text in Powershell is too tricky. There are various quirks. For example, using Write-Host in a script causes naked text to stop being output. Format-XXX can't be used inside scripts. Etc. This whole area could use some documentation. Someone needs to write a "Powershell Gotchas" article. But the very worst thing about Powershell is when you have to work on a machine that doesn't have it. Mike |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: No output from write-output Mike, these are only "gotchas" if they're not clearly explained. Please use http://connect.microsoft.com to file doc bugs. If you can include an e-mail address, I'd be happy to let you review the fixes. -- June Blender [MSFT] Windows PowerShell Documentation Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "mikes.net" wrote: > On Apr 10, 8:03 pm, "Marcel J. Ortiz [MSFT]" > <mos...@online.microsoft.com> wrote: > > > Why didn't I get a line saying > > > I got World > > > > Because write-output doesn't write to the console. It sends objects down > > the pipeline which measure-command will then discard. measure-object will > > only output the TimeSpan object for how long it took. write-host will write > > to the console. > > So if you change write-output to write-host you'll get what you expected. > > In my opinion outputting text in Powershell is too tricky. There are > various quirks. For example, using Write-Host in a script causes > naked text to stop being output. Format-XXX can't be used inside > scripts. Etc. This whole area could use some documentation. Someone > needs to write a "Powershell Gotchas" article. > > But the very worst thing about Powershell is when you have to work on > a machine that doesn't have it. > > Mike > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Write-Output is bleeding into a pipe why | PowerShell | |||
| Formatting output with write-host | PowerShell | |||
| write-output array without C/R | PowerShell | |||
| Duplicating import-csv with write-output | PowerShell | |||
| write whatif output to file | PowerShell | |||