VOGONS

Common searches


Can DOSBox set the ErrorLevel on exit?

Topic actions

  • This topic is locked. You cannot reply or edit posts.

First post, by RrnR

User metadata
Rank Newbie
Rank
Newbie

I have DOSBox set up so that I can pass it command lines which previously were called directly from batch files (I call it from a wrapper batch file that checks to see if the platform is 64-bit - if it isn't, it just executes the command line, otherwise it fires up DOSBox and passes the command line to it - that way the batch files run on both 32 and 64-bit systems).

Anyway, these command lines usually invoke a build process that sets ErrorLevel according to success or failure. When the command line executes inside DOSBox, how can I pass the resulting ErrorLevel back to the process that invoked DOSBox when DOSBox exits?

Reply 3 of 12, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

not sure if passing the emulated error code back to host is a good idea.
As there is not really a problem in dosbox itself if your application fails to find a file.

Water flows down the stream
How to ask questions the smart way!

Reply 5 of 12, by RrnR

User metadata
Rank Newbie
Rank
Newbie

@Qbix I disagree. When you are using DOSBox essentially as a 32-bit command processor emulator for a single command line, then it makes the emulation more complete. I'm not suggesting it become a permanent feature, but a DOSBox.exe command line option like -SetErrorLevel.

@Malvineous I like your idea!

I just tried it however, and I can't see how to get ErrorLevel

echo %ErrorLevel% ><some path>\ErrorLevel.txt

doesn't work, as DOSBox doesn't set an environment variable to ErrorLevel. Any suggestions?

Reply 6 of 12, by collector

User metadata
Rank l33t
Rank
l33t

DOSBox's emulation was never meant to be that complete or accurate. It is meant for compatibility with decent performance with DOS games. There are other emulators out there if you need more.

The Sierra Help Pages -- New Sierra Game Installers -- Sierra Game Patches -- New Non-Sierra Game Installers

Reply 7 of 12, by Joey_sw

User metadata
Rank Oldbie
Rank
Oldbie

if you can access debug.exe that usually supplied with Microsoft OS, you can create a .COM executable file to output the Errorlevel.
My version should works if errorlevel are lower than 10.

0100  B44D          MOV     AH,4D
0102 CD21 INT 21
0104 88C2 MOV DL,AL
0106 80C230 ADD DL,30
0109 B402 MOV AH,02
010B CD21 INT 21
010D B44C MOV AH,4C
010F CD21 INT 21

you can make that .COM file using hex-editor program too.

B4 4D CD 21 88 C2 80 C2-30 B4 02 CD 21 B4 4C CD 21

Its depends if above int 21h functions were implemented in dosbox or not.
But it should works if you're booting using MS-DOS boot-image in dosbox.

-fffuuu

Reply 9 of 12, by Malvineous

User metadata
Rank Oldbie
Rank
Oldbie

If DOSBox did set the errorlevel to an environment variable, then it would no longer be emulating DOS. The %errorlevel% environment variable wasn't added until cmd.exe came about. See ERRORLEVEL is not %ERRORLEVEL%.

Joey_sw's idea is very good, because otherwise I think you have to resort to something terrible like this, to keep within DOS compatibility:

IF ERRORLEVEL 0 ECHO 0 > E.TXT
IF ERRORLEVEL 1 ECHO 1 > E.TXT
IF ERRORLEVEL 2 ECHO 2 > E.TXT
...

Reply 10 of 12, by RrnR

User metadata
Rank Newbie
Rank
Newbie

I don't see anything wrong with "not emulating DOS". Keeping the faith can be protected from additions to functionality like this by requiring a command line parameter when launching the program, e.g.

DOSBox.exe -AllowExtensions

If this wasn't present then DOSBox would behave as it does now. Developers would then be free to add other enhancements like the GEQ, LEQ, etc operators in IF statements.

Reply 11 of 12, by collector

User metadata
Rank l33t
Rank
l33t

The emphasis of DOSBox will not change and pushing the point will only annoy the DOSBox devs. You might present this to the developers of either vDos or DOSBox-X.

The Sierra Help Pages -- New Sierra Game Installers -- Sierra Game Patches -- New Non-Sierra Game Installers

Reply 12 of 12, by MtheK2

User metadata
Rank Newbie
Rank
Newbie

FYI

I have a simple way to get the feature, the Environment Variable %errorlevel%
that DOSBox-x doesn't seem to want to give us, by merely enhancing the usage of
the previously-supplied 16bit program that gets the previous RC (return code).

As B 4, this does NOT need so many fixed RCs using ECHO and a file to determine
it, and certainly not a different "hypervisor"/emulator, as follows:


1. make a 16-bit MASM program (or use the previously-supplied program for up to 10)
to create a .log file from STDOUT re-direction. Partial code:

006A 0000 DBLWRD WORD ?
006C 00 SAVERC BYTE ?

006D 0003 [ CNTNUM BYTE 3 DUP('0')
30
]
0070 0D RECEND BYTE 0Dh
0071 0A BYTE 0Ah

0000 .CODE

.STARTUP ; prime regs properly

001F B4 4D MOV AH,4Dh ; get prev return code in AL (8bit only)
0021 CD 21 INT 21h
0023 A2 006C R MOV SAVERC,AL

0026 B4 00 MOV AH,0
0028 BB 006D R MOV BX,OFFSET CNTNUM+0
002B BA 0000 MOV DX,0
002E C7 06 006A R 000A MOV DBLWRD,10
0034 F7 36 006A R DIV DBLWRD ; divide by 10
0038 83 C2 30 ADD DX,0030h
003B 88 57 02 MOV [BX+2],DL ; move remainder (3rd digit)
003E BA 0000 MOV DX,0
0041 C7 06 006A R 000A MOV DBLWRD,10
0047 F7 36 006A R DIV DBLWRD ; divide by 10
004B 83 C2 30 ADD DX,0030h
004E 88 57 01 MOV [BX+1],DL ; move remainder (2nd digit)
0051 83 C0 30 ADD AX,0030h
0054 88 07 MOV [BX+0],AL ; move quotient (1st digit)

; send to STDOUT (re-directed to file)...

0056 8A 16 006D R MOV DL,CNTNUM+0
005A B4 02 MOV AH,02h
005C CD 21 INT 21h
005E 8A 16 006E R MOV DL,CNTNUM+1
0062 B4 02 MOV AH,02h
0064 CD 21 INT 21h
0066 8A 16 006F R MOV DL,CNTNUM+2
006A B4 02 MOV AH,02h
006C CD 21 INT 21h

006E 8A 16 0070 R MOV DL,RECEND+0
0072 B4 02 MOV AH,02h
Show last 67 lines
 0074  CD 21			         INT   21h  
0076 8A 16 0071 R MOV DL,RECEND+1
007A B4 02 MOV AH,02h
007C CD 21 INT 21h

007E A0 006C R MOV AL,SAVERC
;* AL contains the return code.

.EXIT

2. make a .txt file as follows (ie: in NOTEPAD):

set ERRORLEVEL=

Make sure the "invisible" CRLF (0D0Ah) is NOT(!!!) at the end of this line.
If you want a different EV set, you can either change the EV name to whatever
(ie: MyEnvVar) or save it to this new EV in step 5.

3. run the 16-bit program in step 1 in DOSBox-x after the program(s) to be
checked, usually in place of something like 'set MyEnvVar=%errorlevel%':

call GETRCBOX.exe >GETRCBOX.log

The O/P .log file is the RC (only up to 255 as AL is only 8bit); ie:

001

and contains a CRLF at the end of the line.
The RC is also set normally, still available in ERRORLEVEL itself
(a la the previously-supplied program).

4. then run these commands after step 3:

type GETRCBOX.txt >GETRCBOX.bat
type GETRCBOX.log >>GETRCBOX.bat

5. then run this newly-created .bat and a TYPE/ECHO command(s) after step 4:

rem (if desired)...
type GETRCBOX.bat

call GETRCBOX.bat

rem (if desired)...
set MyEnvVar=%errorlevel%

rem (if desired)...
echo RC=%errorlevel% /or/ %MyEnvVar%

The RC is shown by DOSBox-x via the TYPE/ECHO command(s) O/P.

Without this technique, the ECHO command shows no RC, as the EV doesn't "exist".
In a way, this kinda duplicates the real "echo RC=%errorlevel%" that is so
valuable in 32bit.

You still have to code the individual ERRORLEVEL checks to do anything else; ie:

if ERRORLEVEL 2 GOTO EXECHIGH
if ERRORLEVEL == 1 GOTO EXECRC1 rem (or %MyEnvVar%)...
if ERRORLEVEL == 0 GOTO EXECRC0
GOTO EXECNEG

6. finally, after step 5 or so, clear the EV for next time (ie: no residue):

set ERRORLEVEL=