in reply to Re: Need Help: Error/die-Handling with Perl & Powershell (updated)
in thread Need Help: Error/die-Handling with Perl & Powershell
see http://stackoverflow.com/questions/17548621/how-to-catch-external-command-failure
for a generic way to catch $lastexitcode
function Exec { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($m +sgs.error_bad_command -f $cmd) ) & $cmd if ($lastexitcode -ne 0) { throw ("Exec: " + $errorMessage) } }
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|