ExitCode from a Powershell script back to Winbat

Started by RorySRut, October 12, 2016, 08:25:11 PM

Previous topic - Next topic

RorySRut

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

stanl

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.

td

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)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade