• Welcome to Theos PowerBasic Museum 2017.

IWshExec.ExitCode Property

Started by José Roca, July 14, 2008, 10:22:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example illustrates the use of the ExitCode property. It contains an intentionally wrong argument "dire" to return an exit code <> 0.


#COMPILE EXE
#DIM ALL
#INCLUDE "WSHOM.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pWsh3 AS IWshShell3
   LOCAL pWshExec AS IWshExec

   pWsh3 = NEWCOM "WScript.Shell"
   IF ISNOTHING(pWsh3) THEN EXIT FUNCTION
   pWshExec = pWsh3.Exec(UCODE$("%comspec% /c dire"))

   DO
      IF pWshExec.Status <> 0 THEN EXIT DO
      SLEEP 100
   LOOP

   PRINT "Status: " pWshExec.Status
   PRINT "Exit code: " pWshExec.ExitCode

   pWshExec = NOTHING
   pWsh3 = NOTHING

   WAITKEY$

END FUNCTION
' ========================================================================================