This is a follow up to yesterday's post - I found that my understanding of the $error variable was wrong - it's actually global.
So here's what I've got now. It's hard to believe this is the best way to solve this problem. Has anyone come up with anything better?
function restartFoo {
$oldErrCount = $error.Count
$procList = get-process foo -ea SilentlyContinue
if ($error.Count -eq $oldErrCount) { $procList | stop-process }
c:\bin\foo.exe
}
It really makes me wonder why systems like PowerShell and T-SQL in Sql Server 2005 don't simply leverage the try/catch/finally semantics of a language like Java or C#. Why reinvent the wheel (and do it so badly, in both of these cases)?
UPDATE (25 Jan 2007): it's $error.Count, not $error.Length...
Posted
Jan 23 2007, 03:27 PM
by
keith-brown