Computing.Net > Forums > Programming > Error level in batch file

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.

Error level in batch file

Reply to Message Icon

Name: nic829
Date: May 7, 2008 at 00:38:02 Pacific
OS: Windows XP
CPU/Ram: Ram: 512Mb
Comment:

i was trying to write a batch file that installs a program, and when there is an error return the error level - except when it has errorlevel 3010

@echo off

:SP2
Start /wait C:\SQLInstall\SP2\SQLServer2005SP2-KB921896-x86-ENU.exe /quiet /allinstances
IF (%ERRORLEVEL% == 0) goto OK
else IF (%ERRORLEVEL% == 3010) goto Restart
else goto ERROR_SP2Install

:OK
echo SP2 Installation finished.
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txt
echo.

:Restart
echo SP2 Installation finished. Restart required.
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txt
echo.

:ERROR_SP2Install
echo Error occurs when installating SQL server 2005 SP2. Error level: %ERRORLEVEL%
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txt

however this doesnt works. Could anyone please help me to come up with a way that I can get the errorlevel when there is an error except when it was errorlevel 3010?



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 7, 2008 at 01:54:48 Pacific
Reply:

IF %ERRORLEVEL%==0 goto OK
IF %ERRORLEVEL%==3010 goto Restart
goto ERROR_SP2Install


0

Response Number 2
Name: nic829
Date: May 7, 2008 at 02:47:10 Pacific
Reply:

Hi Razor,
Thanks for your help, and I have tried with your suggestion. In your suggestion it will always go to ERROR_SP2Install no matter what the errorlevel is, but my intension is going to ERROR_SP2Install only when there is a errorlevel > 0 and not 3010.

To illustrate clearer:
Case 1: errorlevel = 0
then OK
Case 2: errorlevel = 3010
then prompt for reboot
Case 3: all other errorlevel
then return the errorlevel value

is there anyway to do this, or if there is any Case command that i can use in Batch file?


0

Response Number 3
Name: Razor2.3
Date: May 7, 2008 at 02:51:41 Pacific
Reply:

Are you sure you're even getting an errorlevel?


0

Response Number 4
Name: klint
Date: May 8, 2008 at 03:07:11 Pacific
Reply:

Razor, I think an exe file always returns an errorlevel, although if it doesn't set it explicitly it may be random.

Since the original poster says that it always goes to ERROR_SP2Install, this means that his program is always returning an errorlevel other than 0 or 3010.

nic829, have you tried inserting echo %errorlevel% just before the goto commands that Razor gave you, to see exactly what error level you are getting?


0

Response Number 5
Name: Razor2.3
Date: May 8, 2008 at 04:10:04 Pacific
Reply:

Razor, I think an exe file always returns an errorlevel, although if it doesn't set it explicitly it may be random.
You would think, but START is a built-in, and not an actual program. I seem to remember it doing some funky things with errorlevel, but I could be wrong.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: May 10, 2008 at 00:36:53 Pacific
Reply:

I think the problem is START.

Presumably, START succeeds and sets 0.

Worse yet, using START the bat goes on it's way and doesn't care what the exe is doing. I see no need for START.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: klint
Date: May 12, 2008 at 01:58:31 Pacific
Reply:

The START/WAIT command is presumably there to pause the batch file until the executable it invokes returns. Otherwise, it will run the executable and the batch will continue running concurrently. When I tried it, START forwarded the errorlevel returned by the executable.


0

Response Number 8
Name: nic829
Date: May 13, 2008 at 19:50:07 Pacific
Reply:

Thanks you all, but I dont think the problem is caused by the start.

So i've tried Razor's method:
IF %ERRORLEVEL%==0 goto OK
IF %ERRORLEVEL%==3010 goto Restart
goto ERROR_SP2Install

Normally my batch should return an errorlevel 3010, and therefore should be going to this: IF (%ERRORLEVEL% == 3010) goto Restart
however it never goes. Instead it directly goes to this: goto ERROR_SP2Install

Is it in batch file we cannot do the If-Then-else thing?


0

Response Number 9
Name: klint
Date: May 14, 2008 at 08:00:06 Pacific
Reply:

Could you please add the following line just before these IF statements, and post your results here.

echo Actual errorlevel is %ERRORLEVEL%


0

Response Number 10
Name: Mechanix2Go
Date: May 14, 2008 at 08:20:36 Pacific
Reply:

"Thanks you all, but I dont think the problem is caused by the start."

LOL

easy to find out


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: klint
Date: May 14, 2008 at 10:37:22 Pacific
Reply:

I think it actually is going to Restart. But you think that it is not. That's because you haven't got a "goto :end" at the end of each labelled section, and therefore the flow of control falls through from Restart to ERROR_SP2Install.


0

Response Number 12
Name: Mechanix2Go
Date: May 14, 2008 at 14:49:01 Pacific
Reply:

"falls through"

yep, that'll do it


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Error level in batch file

Date Routines in Batch Files www.computing.net/answers/programming/date-routines-in-batch-files/15590.html

%DATE% in batch files with win98 www.computing.net/answers/programming/date-in-batch-files-with-win98/4007.html

Progress bar in batch file www.computing.net/answers/programming/progress-bar-in-batch-file/14919.html