Computing.Net > Forums > Disk Operating System > DOS BATCH

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS BATCH

Reply to Message Icon

Name: Debbie
Date: August 7, 2000 at 14:28:49 Pacific
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: DoOMsdAY
Date: August 7, 2000 at 15:51:33 Pacific
Reply:

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...


0

Response Number 2
Name: JR
Date: August 8, 2000 at 02:15:17 Pacific
Reply:

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.


0

Response Number 3
Name: DoOMsdAY
Date: August 8, 2000 at 05:48:17 Pacific
Reply:

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 > nul

On 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.


0

Response Number 4
Name: deadly
Date: August 9, 2000 at 02:24:28 Pacific
Reply:

this prog? it works in windows and dos? isnt this what i was asking 20+ posts ago?


0

Response Number 5
Name: DoOMsdAY
Date: August 9, 2000 at 05:37:57 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Laurence
Date: August 10, 2000 at 00:02:22 Pacific
Reply:

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#iferrorlevel

If 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=


0

Response Number 7
Name: DoOMsdAY
Date: August 10, 2000 at 04:48:26 Pacific
Reply:

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! :)


0

Response Number 8
Name: JR
Date: August 11, 2000 at 12:33:46 Pacific
Reply:

Sorry, I was wrong.


0

Sponsored Link
Ads by Google
Reply to Message Icon

help.... return key in command lin...



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: DOS BATCH

Dos Batch File Commands www.computing.net/answers/dos/dos-batch-file-commands/11921.html

File Size in DOS Batch file www.computing.net/answers/dos/file-size-in-dos-batch-file/3105.html

DOS Batch file to FTP files from UNIX www.computing.net/answers/dos/dos-batch-file-to-ftp-files-from-unix/2105.html