PSS 2014 How to return an exit code from Windows Package

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
mkedaj
Posts: 6
Joined: Sun Mar 03, 2013 12:42 pm

PSS 2014 How to return an exit code from Windows Package

Post by mkedaj » Tue Jun 24, 2014 3:04 am

Hi,

I want to package a script as Windows exe.
My sample code:
PowerShell Code
Double-click the code block to select all.
$script:ExitCode = 2
$global:ExitCode = 3
Packaged with "V3 Host (Command line) x64" :
PowerShell Code
Double-click the code block to select all.
PS C:\Test> .\TestExit.exe;$?;$LASTEXITCODE
False
3
Packaged with "V3 Host (Windows) x64" :
PowerShell Code
Double-click the code block to select all.
PS C:\Test> .\TestExit.exe;$?;$LASTEXITCODE
True
Is there a way to let the Windows version return an exit code?

Comment on the result of the command line version for those who are interested in:
If only $script:ExitCode is defined this value is the return code of the package.
If also $global:ExitCode is defined the global value is the return code of the package.
If the value of $ExitCode isn't numeric (e.g. "y" or $null) then $? is True and $LASTEXITCODE is 0.
Numeric strings ($ExitCode = "123") will work like numeric values.

Martin