WinRb / WinRM

Ruby library for Windows Remote Management
Apache License 2.0
412 stars 117 forks source link

Uncaught Powershell exception is translated to exit code 0 #338

Open wwylele opened 2 years ago

wwylele commented 2 years ago

I am not sure whether Windows itself is at fault or this is something that can be fixed in this library. Feel free to close this if the root problem is in Windows.

When I use WinRM to run powershell script, if an exception is thrown to the top level without being caught, it logs the error message in stderr, but the exit code is still 0 indicating success. This is confusing because if I run a powershell file locally, the exit code would be 1 if an exception is thrown. There isn't any method to explicitly check uncaught exception, either, so it is cumbersome to work with scripts that can throw.

The version we are using is 2.2 and I can't change it easily. Please let me know if there is any difference between 2.2 and the latest.