Jump to content

Recommended Posts

Posted

The codes are as below:

when I try to load a new machine by ghosting from image, I use the command:

ghost -clone, mode=load,src=X:\Backup.gho,dst=1 -ntil -sure -auto

then followed the below codes

SET E=

FOR %%! IN (1 2) DO IF ERRORLEVEL %%!00 SET E=%%!

SET !=0 1 2 3 4 5 6 7 8 9

IF ERRORLEVEL ?SET !=0 1 2 3 4 5

IF ERRORLEVEL : FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%!0 SET E=%E%%%!

IF NOT ERRORLEVEL * SET !=0 1 2 3 4 5 6 7 8 9

FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%! SET E=%E%%%!

IF NOT %E%==0 goto ERROR

The codes can help detect whether the process could be finished successful during ghosting, if we interrput the ghosting process, it really could goto ERROR label.

But I don't understand how come that make this happen? Some command or expression I even havenot seen before.

Could anyone help me on this ? or provide some links to introduce some information about this. very appreciated.


Posted

From the code you have posted, I cannot understand what it is you are trying to achieve.

Is it not just better to inform you of an error if one existed as a result of the previous command.

@echo off
ghost -clone, mode=load,src=X:\Backup.gho,dst=1 -ntil -sure -auto

::if errorlevel returned is 1 or greater then go to label named onerr
if errorlevel 1 goto onerr

::any further code on success here
echo. The operation was successful
pause

goto :eof

:onerr
::any further code on failure here
echo. The operation failed
pause

Posted

Thanks for your reply.

I just don't understand what this means

"IF ERRORLEVEL ?SET !=0 1 2 3 4 5"

IF ERRORLEVEL : FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%!0 SET E=%E%%%!

Errorlevel with ":" I never see this usage.

Posted

You would need to provide the entire file and the ghost documentation on its errorlevels in order for me to attempt to make some working code.

Looking at what is there, I've got no idea what is needed only that the entire batch code presented is one of the most meaningless I've ever seen.

The producer of the code appears to have no idea whatsoever of what errorlevels are or how they work.

Posted (edited)

Thanks very much for your kind reply,here is the codes

@echo off

set version=Beta1
set imagefile=test.GHO

Z:\gdisk 2 /del /all
Z:\gdisk 2 /cre /pri
Z:\gdisk 1 /del /all
Z:\gdisk 1 /cre /pri
Z:\ghost -clone,mode=PLOAD,src=Z:\%imagefile%:1,dst=1:1 -ntil -auto -sure -fx -PREFGHST -FFX -FFI -FFS

SET E=
FOR %%! IN (1 2) DO IF ERRORLEVEL %%!00 SET E=%%!
SET !=0 1 2 3 4 5 6 7 8 9
IF ERRORLEVEL ?SET !=0 1 2 3 4 5
IF ERRORLEVEL : FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%!0 SET E=%E%%%!
IF NOT ERRORLEVEL * SET !=0 1 2 3 4 5 6 7 8 9
FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%! SET E=%E%%%!
IF NOT %E%==0 goto ERROR

Z:\ghost -clone,mode=PLOAD,src=Z:\%imagefile%:2,dst=2:1 -ntil -auto -sure -fx -PREFGHST -FFX -FFI -FFS
rem -fnu -fna

SET E=
FOR %%! IN (1 2) DO IF ERRORLEVEL %%!00 SET E=%%!
SET !=0 1 2 3 4 5 6 7 8 9
IF ERRORLEVEL ?SET !=0 1 2 3 4 5
IF ERRORLEVEL : FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%!0 SET E=%E%%%!
IF NOT ERRORLEVEL * SET !=0 1 2 3 4 5 6 7 8 9
FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%! SET E=%E%%%!
IF NOT %E%==0 goto ERROR

goto END

:ERROR
echo.
echo The Ghosting process has failed!!!
goto QUIT

:END

:QUIT

That's the entire code,it is working for machines with 2 harddisks. When ghosting process is interrupted by Ctrl+C or other methods, the codes can detect this ,and turn to :error label.

Edited by my44186680
Posted

The entire errorlevel section is a pointless waste of space, as I stated in my first response all you need to do is replace both of the sections containing

SET E=
FOR %%! IN (1 2) DO IF ERRORLEVEL %%!00 SET E=%%!
SET !=0 1 2 3 4 5 6 7 8 9
IF ERRORLEVEL ?SET !=0 1 2 3 4 5
IF ERRORLEVEL : FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%!0 SET E=%E%%%!
IF NOT ERRORLEVEL * SET !=0 1 2 3 4 5 6 7 8 9
FOR %%! IN (%!%) DO IF ERRORLEVEL %E%%%! SET E=%E%%%!
IF NOT %E%==0 goto ERROR

with

if errorlevel 1 goto ERROR

or

if not errorlevel 0 goto ERROR

All you are in effect doing is letting them know that an error occurred.

Also if they needed to see that error message you would need to either be running in a pre-opened console window or add a command to pause the end before the window closed without reading it.

Another thing you may or may not be aware of is that if an error of any sort occurs whilst performing the clone of image 1 onto your first disk, the script will not even bother cloning the other image to the second disk.

Posted

Oh, it is amazing, I will replace the codes with your post, and have a test. Thank you very much for your help, actually I have been confused for this a long time.

;)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...