TL;DR: You can send an exit 1
to exit with a return code of 1 (or any number other than 0), which means it failed for some reason.
Normally (and under specific circumstances) PowerShell scripts exit with a code of 0. Most other applications return an exit code of 0 whenever they are 'successfully completed,' and without any sort of exception or error that the program is consciously aware occurred.
If you're trapping the exit code in the WPF, you could report whether it was successful (exit 0
inserted at some point in your code, or let it finish as expected), or if it failed (exit
of any other number) - at which point you would want to consider reporting unique exit codes specific to the reasons that occurred wrong.
Consider also looking into try
, catch
, and throw
as they're quite useful, as well.
EDIT: As a final note, take a good look at how %errorLevel%
(where the exit code is stored) is handled under some unique situations. %errorLevel%
is what you want to focus on, if you use exit
codes.