Mail Archives: djgpp/2002/01/13/18:31:51
"Pedro Izecksohn" <izecksohn AT yahoo DOT com> wrote in
news:000c01c19c85$ba51f000$2de1a0c8 AT rjo DOT virtua DOT com DOT br:
> Hi, What do happen when main return 1 ? Does the program passes
> this value to DOS's ERRORLEVEL ?
yes.
> Why in my code errorlevel isn't catching
> the 1 value ? I'm attaching here the .cc and the .bat codes.
did you, by any chance, give the same name to your executable and batch
files? if then, dos will execute the exe not the bat file.
try the following:
=== begin: t.bat ===
@echo off
erl
if errorlevel 1 goto echo_1
if errorlevel 0 goto echo_0
:echo_1
echo 1
goto end
:echo_0
echo 0
:end
=== end: t.bat ===
btw, if you use the batch file you posted:
> erl
> if errorlevel 1 echo 1
> if errorlevel 0 echo 0
you will have both 1 and 0 echoed on the screen because in dos
if errorlevel n
tests if errorlevel is at least n. so, to make sure errorlevel is equal to
0, you have to do
if not errorlevel 1
=== begin: modified t.bat to test for errorlevel == 1 ===
@echo off
erl
if not errorlevel 1 goto echo_0
if errorlevel 1 goto echo_1
:echo_1
if not errorlevel 2 echo 1
goto end
:echo_0
echo 0
:end
=== end: modified t.bat to test for errorlevel == 1 ===
hth.
Sinan.
--
--------------------------------
A. Sinan Unur
http://www.unur.com/
- Raw text -