In PowerShell, what is the difference between $?
and $LastExitCode
?
I read about automatic variables, and it said:
$? Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.
$LastExitCode Contains the exit code of the last Windows-based program that was run.
In the definition of $?
it doesn't explain what succeed and fail mean.
I ask because I presumed that $?
is True if and only if $LastExitCode is 0, but I found a surprising counter-example: $LastExitCode=0 but $?=False in PowerShell. Redirecting stderr to stdout gives NativeCommandError.