I have a WinForms project - let's call it Child.exe. Child.exe is called from another compiled powershell script - let's call it Parent.exe. I am trying to retrieve the exist code from Child.exe and do something with that in Parent.exe.
In Child.exe I have tried:
$global:exitCode = 0
$form.Close()
From Parent.exe $LASTEXITCODE is blank.
In Parent.exe I have tried:
$var = & Child.exe
wait-process -Name Child
$var is empty after Child.exe closes.
Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.190
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.19042.0
Get exit code from Winforms packaged EXE
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Get exit code from Winforms packaged EXE
Only the "exit" command can set the exit code.
The following discussion should give you a handle on how this works.
https://stackoverflow.com/questions/502 ... ell-script
The following discussion should give you a handle on how this works.
https://stackoverflow.com/questions/502 ... ell-script
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Get exit code from Winforms packaged EXE
$ExitCode is the correct variable to set in your child process.
It seems there is a bug in PowerShell that prevents you from getting the exit code of a child process
with separate wait.
It is illustrated here:
https://stackoverflow.com/questions/102 ... ad-of-wait
Depending on your needs, the following post may have some solutions:
https://stackoverflow.com/questions/102 ... ad-of-wait
It seems there is a bug in PowerShell that prevents you from getting the exit code of a child process
with separate wait.
It is illustrated here:
https://stackoverflow.com/questions/102 ... ad-of-wait
Depending on your needs, the following post may have some solutions:
https://stackoverflow.com/questions/102 ... ad-of-wait
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.