Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Error level in batch file

Original Message
Name: nic829
Date: May 7, 2008 at 00:38:02 Pacific
Subject: Error level in batch file
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?


Report Offensive Message For Removal

Response Number 1
Name: Razor2.3
Date: May 7, 2008 at 01:54:48 Pacific
Subject: Error level in batch file
Reply: (edit)
IF %ERRORLEVEL%==0 goto OK
IF %ERRORLEVEL%==3010 goto Restart
goto ERROR_SP2Install


Report Offensive Follow Up For Removal

Response Number 2
Name: nic829
Date: May 7, 2008 at 02:47:10 Pacific
Subject: Error level in batch file
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: May 7, 2008 at 02:51:41 Pacific
Subject: Error level in batch file
Reply: (edit)
Are you sure you're even getting an errorlevel?

Report Offensive Follow Up For Removal

Response Number 4
Name: klint
Date: May 8, 2008 at 03:07:11 Pacific
Subject: Error level in batch file
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: May 8, 2008 at 04:10:04 Pacific
Subject: Error level in batch file
Reply: (edit)
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.

Report Offensive Follow Up For Removal

Response Number 6
Name: Mechanix2Go
Date: May 10, 2008 at 00:36:53 Pacific
Subject: Error level in batch file
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 7
Name: klint
Date: May 12, 2008 at 01:58:31 Pacific
Subject: Error level in batch file
Reply: (edit)
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.

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Error level in batch file

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC