![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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-Error doesn't write anyting I created a new object using new-object PSObject and added a ScriptMethod. In some cases the method should write error, but it doesn't. Consider this code: $ErrorActionPreference='stop' New-Object PSObject | Add-Member scriptmethod w {write-error "NO"} - pass | % { $_.w() }; ^__ this works, error is written and the execution is stopped. But the following code doesn't write anything even when it should: $ErrorActionPreference='continue' #this is the only change New-Object PSObject | Add-Member scriptmethod w {write-error "NO"} - pass | % { $_.w() }; The error is added to $error, but not written to console. Note that this works: $ErrorActionPreference='continue' #this is the only change write-error "error"; get-date Why write-error doesn't work inside ScriptMethod? |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Write-Error doesn't write anyting What version of Powershell if v2 what does $psversiontable show? The below is what I'm seeing with CTP3: 1) Setting the Powershell variable $ErrorActionPerference to 'stop' does not stop Write-Error from being sent to the console. 2) Unfortunately in your case what I'm seeing is looks to be a bug in Powershell. Here is what I mean (ErrorActionPerference is in the default state) $o = New-Object PSObject | Add-Member -MemberType ScriptMethod {write-error hello} -Name w -pass $o.w ## No surprise here, this dump the properties of this member which is a scriptmethod $o.w() ## nothing is written to the console Create a new PSObject ($o1) but use Write-Host/Warning/Output to outuput the message $o1.w() ## this will write to the console Now set ErrorActionPreference to "stop" then when you call $o.w() the error I see is not "hello" but "can't call w with 0 arguments ...." are you seeing the same? While setting the preference did write an error to the console its not what I expected. The expected results should be "Hello". This is the reason I think you should submit a bug report. bob "stej" wrote: Quote: > I created a new object using new-object PSObject and added a > ScriptMethod. In some cases the method should write error, but it > doesn't. > > Consider this code: > $ErrorActionPreference='stop' > New-Object PSObject | Add-Member scriptmethod w {write-error "NO"} - > pass | % { $_.w() }; > ^__ this works, error is written and the execution is stopped. > > But the following code doesn't write anything even when it should: > $ErrorActionPreference='continue' #this is the only change > New-Object PSObject | Add-Member scriptmethod w {write-error "NO"} - > pass | % { $_.w() }; > > The error is added to $error, but not written to console. Note that > this works: > $ErrorActionPreference='continue' #this is the only change > write-error "error"; get-date > > Why write-error doesn't work inside ScriptMethod? > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Write-Error doesn't write anyting On May 11, 11:31*pm, Bob Landau <BobLan...@xxxxxx> wrote: Quote: > What version of Powershell if v2 what does $psversiontable show? > The below is what I'm seeing with CTP3: Quote: > 1) Setting the Powershell variable $ErrorActionPerference to 'stop' does not > stop Write-Error from being sent to the console. console, it's ok. But the execution of the script/function/.. should stop. Quote: > 2) Unfortunately in your case what I'm seeing is looks to be a bug in > Powershell. Here is what I mean (ErrorActionPerference is in the default > state) > > $o = New-Object PSObject | Add-Member -MemberType ScriptMethod {write-error > hello} -Name w -pass > $o.w *## No surprise here, *this dump the properties of this member which is > a scriptmethod > > $o.w() *## nothing is written to the console > > Create a new PSObject *($o1) but use Write-Host/Warning/Output to outuput > the message > > $o1.w() ## this will write to the console > > Now set ErrorActionPreference to "stop" then when you call $o.w() the error > I see is not "hello" but > > "can't call w with 0 arguments ...." > > are you seeing the same? > > While setting the preference did write an error to the console its not what > I expected. The expected results should be "Hello". > > This is the reason I think you should submit a bug report. $o = New-Object PSObject | Add-Member -MemberType ScriptMethod {write- error hello } -name w -pass $ErrorActionPreference = 'continue' $o.w() # prints nothing $ErrorActionPreference = "stop" $o.w() #stops and writes error Quote: Quote: >> Exception calling "w" with "0" argument(s): "Command execution stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: hello" |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Write-Error doesn't write anyting Stej, Yes, we are both seeing the same thing; as I said in the previous post I believe you found a bug. Do you know how to report it? Do you want to report it? For now a work-around is to use Write-Warning which for me will work using v2 CTP3. At least the users of your script will be able to differentiate normal output from output to be concerned about. "stej" wrote: Quote: > On May 11, 11:31 pm, Bob Landau <BobLan...@xxxxxx> > wrote: Quote: > > What version of Powershell if v2 what does $psversiontable show? > > The below is what I'm seeing with CTP3: > Quote: > > 1) Setting the Powershell variable $ErrorActionPerference to 'stop' does not > > stop Write-Error from being sent to the console. > console, it's ok. But the execution of the script/function/.. should > stop. > Quote: > > 2) Unfortunately in your case what I'm seeing is looks to be a bug in > > Powershell. Here is what I mean (ErrorActionPerference is in the default > > state) > > > > $o = New-Object PSObject | Add-Member -MemberType ScriptMethod {write-error > > hello} -Name w -pass > > $o.w ## No surprise here, this dump the properties of this member which is > > a scriptmethod > > > > $o.w() ## nothing is written to the console > > > > Create a new PSObject ($o1) but use Write-Host/Warning/Output to outuput > > the message > > > > $o1.w() ## this will write to the console > > > > Now set ErrorActionPreference to "stop" then when you call $o.w() the error > > I see is not "hello" but > > > > "can't call w with 0 arguments ...." > > > > are you seeing the same? > > > > While setting the preference did write an error to the console its not what > > I expected. The expected results should be "Hello". > > > > This is the reason I think you should submit a bug report. > I tried this code: > > $o = New-Object PSObject | Add-Member -MemberType ScriptMethod {write- > error hello } -name w -pass > $ErrorActionPreference = 'continue' > $o.w() # prints nothing > $ErrorActionPreference = "stop" > $o.w() #stops and writes error Quote: Quote: > >> Exception calling "w" with "0" argument(s): "Command execution stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: hello" > It should work for you in the same way. > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Write-Error doesn't write anyting I asked at twitter how to report a bug, nobody answered. Do you know where to go? |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Write-Error doesn't write anyting On May 26, 11:02*pm, stej <cerna.ze...@xxxxxx> wrote: Quote: > I asked at twitter how to report a bug, nobody answered. Do you know > where to go? and you should be able to submit feedback. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Write-Error doesn't write anyting |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Cannot write to drive "Media is write protected" | Vista hardware & devices | |||
| how to get powershell to write to event log or write a log file? | PowerShell | |||
| Write error | System Security | |||
| The disk is write-protected. Remove the write-protection or... | Vista General | |||
| newline in Write-Debug or Write-Verbose | PowerShell | |||