Computing.Net > Forums > Programming > how to set error control in this?

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.

how to set error control in this?

Reply to Message Icon

Name: alwaysk2
Date: August 16, 2008 at 12:27:20 Pacific
OS: windows 2000 server
CPU/Ram: 8 GHZ/16GB DDR2
Product: IBM
Comment:

hi all,

i have made a batch file which is working perfectly now.. but i don't know how to set ERROR CONTROL in this batch file can any one suggest me any ideas by how can i set error control.

here is the batch file

===========================================
@echo off
TITLE --- ONCOURSE UPLOADING ---

::SET UP CURRENT DATE TO MMDDYYYY FORMAT
set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1f

:: MAPPING SERVER PATH FOR DIRECT COPY
net use Z: \\server1\d$\test test@test1/USER:test.com\admn /PERSISTENT:YES

cls
:: ASKING USER TO ENTER PREVIOUS DAY'S DATE
set /P d= PLEASE ENTER DATE : -

::SET UP DESTINATION PATH WHERE ALL THE OPERATIONS WILL OCCUR
set e=D:\ONCOUR~1\AXA\Output\%d%

::SET UP SYSTEMS XCOPY VARIABLE
set copyme=xcopy /s /c /d /e /h /i /r /y

ECHO.

IF /I %d% LSS %Pdate% GOTO DO
) ELSE
goto :error
)

:DO

Z:
CD Output\AXAHCF~1
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AX15EC~1
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAHCF~4
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAUB9~3
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAUB9~4
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp

CLS
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
COLOR 1f
CLS
echo -- PLEASE VERIFY THE SOURCE AND DESTINATION FILES IF NOT MATCHING PRESS CTRL+C --
echo.
echo.
echo - BELOW LISTED FILES HAVE BEEN COPIED -
echo -----------
echo.
echo LIST OF FILES FROM SOURCE LOCATION
echo.
echo.
:: VERIFYING SOURCE & DESTINATION TO CHECK ANY ERRORS AND COMPARE FILES
dir /B z:\Output\AXAHCF~1\%d%
dir /B z:\Output\AX15EC~1\%d%
dir /B z:\Output\AXAHCF~4\%d%
dir /B z:\Output\AXAUB9~3\%d%
dir /B z:\Output\AXAUB9~4\%d%
echo.
echo.
echo LIST OF FILES WHICH JUST COPIED ON ADMIN3
echo.
echo.
dir /B %e%
echo.
echo TOTAL FILES :
dir "%e%" /a-d /b/s |find /v /c "::"
echo.
echo.
ECHO PRESS ANY KEY TO OPEN THE SUMMARY FILES
pause>nul
CLS
echo (-- PLEASE COMPARE WITH E-MAIL --)
echo.
echo.
COLOR 1f
GOTO output
:output
@echo off
type c:\ONCOUR~1\axatemp\*summary.txt
ECHO.
echo.
echo.
echo PRESS ANY KEY TO UNZIP THE FILES AND MAKE IT READY TO UPLOAD
PAUSE>nul

:: DELETING THE TEMPERORY FOLDER
rd /S /Q c:\ONCOUR~1\axatemp
CLS
COLOR EF


::MAKING A ZIP FILE IN SPECIFIED NAME AXA_<ENTERED DATE>.ZIP AND DELETING THE UNNECESSARY FILES
goto zip1
:zip1
"C:\Program Files\7-Zip\7z.exe" a -tzip "AXA_%d%.zip" -r "%e%\*" >> c:\ONCOUR~1\%d%_log.log
move /y *.ZIP %e% >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.txt >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.xls >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.h* >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.u* >> c:\ONCOUR~1\%d%_log.log
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
COLOR 1A
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo - OUTPUT HAS BEEN SUCCESSFULLY GENERATED -
echo -------------
PAUSE>nul
EXIT

:error
CLS
COLOR 1A
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo --- THE %D% IS NOT ALLOWED ---
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ---- PLEASE CONTACT SYSTEM ADMINISTRATOR----
echo.
pause>NUL
EXIT
=============================

K2™
System/Network Engineer



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: August 17, 2008 at 04:26:36 Pacific
Reply:

What do you mean by "set error control"?

In a critical batch script you can check for the success of any command by inspecting the %ErrorLevel% system variable after the issued command, e.g.

copy .....
if errorlevel 1 <Command Failed: Do something>

Beware the statement "if errorlevel #" is TRUE for ErrorLevel greater or equal the value coded, so in the previous example the statement following the If is executed for any errorlevel greater than 0 usually set for Success.

Many tools and utilities too set the errorlevel variable for execution checking.


0

Response Number 2
Name: alwaysk2
Date: August 17, 2008 at 05:55:16 Pacific
Reply:

thank you for you reply bro. but i m not getting much what are you saying. could you describe it with more details and any example or could you describe me various errorlevels if you can. thx

K2™
System/Network Engineer


0

Response Number 3
Name: Nigel Spike
Date: August 17, 2008 at 06:45:54 Pacific
Reply:

A batch file consists of a number of commands, each of which may be tested for error level.

In your example:
::SET UP CURRENT DATE TO MMDDYYYY FORMAT
set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1f

SET and COLOR are both commands, but of them only COLOR can be tested for errorlevel.

Nigel

This is just a sig


0

Response Number 4
Name: IVO
Date: August 17, 2008 at 07:28:59 Pacific
Reply:

Stated that you do not explain what you are trying to achieve, there is no more to add what I said in my previous post to.

Each native batch command posts a return code into the ErrorLevel system variable that can be checked to examine the result of the action. The values set depend on the specific command, but usually 0 means the execution was succesful and greater codes show problems.

The statement "if ErrorLevel #" (with ErrorLevel NOT embraced by %) is used to perform the test and start subsequent actions. Beware the statement "if errorlevel #" is TRUE for ErrorLevel greater or equal the value coded.

So if you want to send a message if the Find command did not find the string "hello" code

find "hello" < myfile
if errorlevel 1 echo "hello" not found

or to check for a positive result

find "hello" < myfile
if not errorlevel 1 echo "hello" found

The ErrorLevel variable can be also checked by coding

if %errorlevel% equ # (or geq, lss and so on...)

To know more about type if /? at prompt.

I hope this fits your needs.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: how to set error control in this?

How to set java classpath in vista www.computing.net/answers/programming/how-to-set-java-classpath-in-vista/15739.html

how to compile C program in edit pl www.computing.net/answers/programming/how-to-compile-c-program-in-edit-pl/8975.html

How to set priority? www.computing.net/answers/programming/how-to-set-priority/13685.html