Apparently a "scope" issue. My goal was for the script to be able to communicate an exit code to my hosting application. If I have the pipeline.Invoke exceute an "exit 123" string I get my SetShouldExit called but If I invoke a script that exits with an exit code, I do not. And the only way I could find any sort of exit code from the current script was to fetch $LastExitCode from the session variables but it even retained its value between scripts in the same runspace if a subsequent script did not do something to reset the value. Not sure what the best "solution" is or if one is really needed but it feels inconsistent and incomplete the way it is. My suggestion would be to always set $LastExitCode when a script ends or at least have some other means to check for an exit code when a script ends which is set to the xxx value if the script exits with "exit xxx". In the meantime, in my hosting case, since I pass in a hosting object anyway, I added a property the script can set to communicate back to the host whether the script failed or not. I think something like this is warranted and hope the PS architects consider some sort of more consistent mechanism as I can't even find the supposed true or false exit code after invoking a script. Thanks, Dave
|