WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: RorySRut on October 12, 2016, 08:25:11 PM

Title: ExitCode from a Powershell script back to Winbat
Post by: RorySRut on October 12, 2016, 08:25:11 PM
I am using a Winbatch compiled script to call a compiled Powershell script so that the powershell script runs silent.  But I cannot get the correct exit code passed back to the Winbatch script from the Powershell script.  For example, I exit the powershell script with exit code 999. I want the winbatch script to exit with the same exit code.  But it always returns 0.  I am exiting the powershell script with: Exit 999   What am I missing?  (the files are all in the same directory)

ScriptDir=DirScript()
EXEPath="TestPS.exe"
Parms=""
RetCode=RunShell(EXEPath, Parms, ScriptDir, @HIDDEN, @GETEXITCODE)
IntControl(1000,RetCode,0,0,0)
Exit
Title: Re: ExitCode from a Powershell script back to Winbat
Post by: stanl on October 13, 2016, 04:54:46 AM
Not sure I can assist with your request, but if you run powershell through the WB CLR you can return to the main script and there are numerous examples in the Tech Database.
Title: Re: ExitCode from a Powershell script back to Winbat
Post by: td on October 13, 2016, 07:40:09 AM
Might try something like the following using your compiled script instead of the powershell exe:

Code (winbatch) Select
hBat=FileOpen("c:\temp\test.bat", "WRITE")
FileWrite(hBat, 'powershell.exe -noprofile -command "Write-output Test; exit 12345"')
FileClose(hBat)
RunWait("c:\temp\test.bat", "")
nExitCode=IntControl(64, 0, 0, 0, 0)
FileDelete("c:\temp\test.bat")
Message("Exit Code Is:", nExitCode)