TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: SANDER SMEENK
from: HANS LUNSING
date: 1996-07-12 19:46:00
subject: ErrorLevel

Hello Sander
On Tuesday, 2 July 1996 13:51:10, you wrote to All:
 SS> Could someone hand me some code to read the returned
 SS> errorlevel from a program? Like, I shell to SCAN, and it returns
 SS> ErrorLevel 3, how do I 'read' this in Basic??
Here it the code you need:
/*
'Pbexec.bas returns an errorlevel from a shelled program with DOS EXEC 
Function
'Written By Ethan Winer for Microsoft Basics
'Converted to Power basic 3.0 by Gary Blydenburgh
'Errorlevel = PBEXEC(Program$,Parameter$)
FUNCTION PBEXEC (Program$,par$) STATIC
  dim block as string * 14
  dim parm as string * 50
  zbuffer$=program$+chr$(0)
  lset parm$ = chr$(len(par$))+par$+chr$(13)
  lset block$ = chr$(0)+chr$(0)+mki$(varptr(parm$))+MKI$(varseg(parm$))
  dummy&=setmem(-500000)
  reg 1, &H4B00
  reg 9,varseg(block$)
  reg 4, strptr(zbuffer$)
  reg 8, strseg(zbuffer$)
  reg 2,varptr(block$)
  call interrupt &H21
  if reg(0) and 1 then
    pbexec=255 'Errorlevel is 255 for and DOS Error
    select case reg (1)
      case 1,2,3,5,8,10,11
      dummy&=setmem(500000)
      exit function
    end select
  end if
  reg 1, &H4D00
  call interrupt &H21
  pbexec=reg(1)
  dummy&=setmem(500000)
END FUNCTION
*/
Friendly greeting you,
Hans Lunsing,           Fido     : 2:281/607.214, 2:282/610.12
                        Internet : jlunsing@doge.nl
--- Terminate 4.00/Pro
 # Origin: BBS De Lauwers For BASIC Programmers! ++3159468840 
(119:3102/101.12)
---------------
* Origin: United Bbs Systems Europe MailGate to -> Fido USA (2:2802/337.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.