Re: File handling
- Posted by Irv <irv at ELLIJAY.COM> Jun 07, 1998
- 691 views
At 08:05 AM 6/7/98 -0400, you wrote: >At 06:44 AM 6/7/98 -0500, Terry Constant wrote: > >>Its been so long since I worked with Command.com, I can't remember if >>there is a way to get exit code info on internal commands. If not there >>would only be one atom. >> >There must be a way. Batch files can branch based on errorlevel. >Also there is interrupt 4Dh that reads the errorlevel returned >on a program exit (I think. Anybody want to wade thru the dos-ref >and find out for sure?) > >>In any case, the return sequence would have information about success or >>failure that could be analyzed. >> >Someone made a suggestion to Rob that system() be made a function, >rather than a procedure, for exactly that purpose. I hope he >sees fit to change it. > I tried the interrupt routine below, but it doesn't work. Why? My guess is because the errorlevel code is destroyed by the first call to errorlevel. Perhaps system() is using (therefore destroying) it before returning? Only Rob can tell us. On the other hand, maybe something is wrong with my interrupt routine. I don't know much about writing these. include machine.e sequence reg_list -- list of register values function ErrorLevel() reg_list = repeat(0, 10) reg_list[REG_AX] = #4D00 -- function: get ERRORLEVEL reg_list = dos_interrupt(#21, reg_list) -- Call DOS interrupt #21 return reg_list end function ? ErrorLevel() system("del test.xxx",2) ? ErrorLevel() -- prints same as above, regardless of whether -- the system call fails or succeeds. Irv ref:Programmer's Technical Reference for MSDOS and the IBM PC Chap.4 Function 4Dh Get Return Code of a Subprocess (WAIT) Get return from functions 31h and 4Dh (ERRORLEVEL) entry AH 4Dh return AH circumstance which caused termination 00h normal termination 01h control-break or control-C 02h critical device error 03h terminate and stay resident (function 31h) AL exit code of subprogram (functions 31h or 4Ch) note 1) The exit code is only returned once (the first time). 2) This call is explicitly supported in the OS/2 1.x DOS Compatibility Box. 3) Many programmers have wondered where DOS stores this information, so they might access it multiple times or set it directly. This is a version-dependent area that changes with every release of DOS.