Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone know either 1) how I can get Windows app to return code to DOS batch file, or 2) how would I go about reading a specific file's contents (either the number 1 or 0 will be in the file and nothing else) and branching to a label based on the data returned?

A simple example:
---[xxx.bat]---
@echo off
find "0" c:\xxx.txt > nul
if errorlevel==1 goto One
if errorlevel==0 goto Zero:One
ECHO Value is One.
goto End:Zero
ECHO Value is Zero.:End
---[xxx.txt]---
1-or-
0
I'm sure there's a cleaner way to do this, but this is how I know to do it...

That doesn't work for Windows programs, so you know. Windows programs does not return any return code at all the way DOS programs do, so I think that's impossible, without doing something like a Windows program that runs the other Windows program, fetches the return code(s) and sends it back to the DOS program via a temporary file or something. I do not know how to program in Windows, though, I would suggest you ask in the Windows forums how to make such a program.
If you have Windows 9x, you can open files in Edit, in "binary mode" and then you will get to see the exact file's content, not with ones and zeroes though, but with decimal ASCII values. You could also use debug. See the DOS help on how to use debug.
If Edit does not satisfy you, search for a freeware hex editor.
Seeing a file as ones and zeroes is not very useful in general, but many hex editors support that, too.

Ummm...my reply was for way 2) of her methods. It would work fine for what she says the situation would be for that. As for a Windows program, all it is is a glorified DOS program with GUI, event-driven interface. Windows apps return codes same as any other app. Just a lot of Windows programmers don't use that cause they probably don't expect someone to Batch their executable and check return codes. An easy example of what I say is true is regsvr32. It's a Windows app. It uses MessageBoxes to communicate to the user. However it was expected to be command line driven, so they exposed return codes. Run this example Batch and see I tell the truth.
@echo off
call regsvr32.exe c:\catchow.ocx
echo %errorlevel%
pause > nul
rem change this to some ocx you have on
rem your system that you know you can
rem register. commx.ocx is specific to
rem my system as it is a serial comm
rem interface i use for one of my apps.
call regsvr32.exe c:\winnt\system32\commx.ocx
echo %errorlevel%
pause > nulOn my system the first one returns 3 cause the file does not exist. The second one returns 0 cause it indeed does AND it registers successfully. It all just depends on how the person wrote the app.

Regsvr32 is a Windows program that runs in a DOS box (console.) It will not run in plain old DOS. I only know of one program that does that. Regedit. It'll run a GUI screen from Windows and a console mode (switch driven) from DOS. Wait a sec. That word "console" sounds awfully familiar. Oh yes. I remember now. It's cause that's exactly what I told you to create 20+ posts ago. A Win32 console application. One that runs in a console but can do Win32 things like messageboxes and Registry access. If you want to make something like Regedit that can do both, I spose you could try a DOS app that includes "windows.h" - cause now that I think about it, I think a Win32 console app will do that automatically. However, I honestly don't know how to make one that works just like Regedit. If you truly need to run in real DOS as well as a DOS box, then good luck to you. If all you're looking to do in real DOS, however, is Registry access - I'd look at the switches available to a person using Regedit under DOS. Those may solve your real DOS problem and allow you to create a full-featured console app for running under Windows.

Reply to "Response Number 1"
This is a bit cleaner.
@echo off
find "0" < c:\xxx.txt > nul
if errorlevel==1 goto One:Zero
ECHO Value is Zero.
goto End:One
ECHO Value is One.:End
OR
@echo off
find "0" < c:\xxx.txt > nul
if not errorlevel==1 ECHO Value is Zero.
if errorlevel==1 ECHO Value is One.
BTW, "if errorlevel==0" is not a valid
test because the errorlevel is always
zero - even when it is not. See:
http://home7.inet.tele.dk/batfiles/basic/chap26.htm#iferrorlevelIf you want to test for all errorlevels:
@echo off
:ERRLVL.BAT v2.11 --------------- Vernon Frazee 12/94
:Purpose: Displays errorlevel set by last program run
:--------------------------------------------
set EL=Errorlevel
for %%x in (A B) do set %%x=0 1 2 3 4 5
if not %EL% 250 set A=%A% 6 7 8 9
if not %EL% 200 set B=%A%
for %%x in (1 2) do if %EL% %%x00 set C=%%x
for %%x in (%B%) do if %EL% %C%%%x0 set D=%%x
if (%C%%D%)==(0) set D=
set C=%C%%D%
for %%x in (%A%) do if %EL% %C%%%x set ErrLvl=%C%%%x
set %EL%=%ErrLvl%
echo %EL%=%ErrLvl%
for %%x in (A B C D EL ErrLvl) do set %%x=

Yeah, I know Laurence. That's cause when you check an errorlevel it is seeing if it is less than or equal to - not just equal to. Hence the order you should check it in with goto's to jump away from the other checks (or some other way to prevent the others from succeeding - like not equal to's.) Thanks for the cleaned up batches though! :)

![]() |
help....
|
return key in command lin...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |