header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
PowerShell SetShouldExit not called and exit with exitcode also does not work
Last Post 29 Jun 2009 08:09 AM by CodeSlinger. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
CodeSlingerUser is Offline
New Member
New Member
Posts:9
Avatar

--
27 Jun 2009 09:18 AM
    If I add the line "exit 12345" to my script, the script will exit but
    SetShouldExit is not called. This method is also not called when the script
    ends normally. If this is normal behavior I feel this is a bug in both cases.
    I can call it from the script using $host but should this not be called by
    default as well?
    CodeSlingerUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    29 Jun 2009 08:09 AM
    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
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer