[<<]Message[>>]    [<<]Author[>>]    [<<]Subject[>>]    [<<]Thread[>>]

Number : 2414 Date : 2002-07-05 Author : Kan Yabumoto Subject : Re: A few tips in batch scripts Size(KB) : 3
XXCOPY's /CB switch makes it fetch the previous exit code (and act accordingly) in the system registry. Since the first line in the batch file should not be dependent on any previous exit code value that may have been left behind in the previous invocation in the same DOS Box, the fist XXCOPY line within a batch script should not use the /CB (or equivalent one like /CE). In the case of calling a common batch file as Garry suggests, we may need a guaranteed mechanism to clear the last-exitcode value. To be honest, we were sometimes a little sloppy in the handling of the exit code. For example, when you run XXCOPY // without any argument XXCOPY /CB0 // basically the same as above XXCOPY will display the short (25-line) help text. The problem (which is our fault) is that v.2.80.3 (our previous release which is widely circulated) did not save the exit code on the occasion. Therefore, with v.2.80.3, the technique suggested by Garry cannot guarantee a resetting of the last-exit code value. --------------------------------------------------- By the way, the "exit code value" that I am referring to here is the value saved by XXCOPY in the system registry for the sake of implementing the /CB switch. XXCOPY does not pay attention to the "actual" exit code which was left behind by a program which was executed immediately before the XXCOPY program in a batch file. Incidentally, XXCOPY's exit code value stored in the system registry is "tied" to the DOS Box's windows handle value in such a way that the scheme is quite safe even when you run multiple XXCOPY scripts from multiple DOS Boxes concurrently. Since the /CB operation relies on the system registry as the persistent "memory" to carry over the previous state of execution, XXCOPY16 (the DOS version) does not support the /CB switch. ---------------------------------------------------- In conclusion, I suggest the use of the following line to achieve the desired effect of clearing the last XXCOPY exit code (works in v.2.80.3 and with new versions) xxcopy /? >nul // clear xxcopy-exit code (the >nul part is optional to suppress the help text). Minor point in Garry's batch example: The proper syntax for in-line comment for XXCOPY is // ... or :: .... Not \\ ..... as Garry suggests. Kan Yabumoto PS: I just saw Melissa's suggestion of using /WE2. Yes, it works well (it was not supported in v.2.80.3) with recent versions. Kan Yabumoto ===================================================== At 2002-07-05 01:29, you wrote: >Kan, > >Seeing your recent post on the use of /ec & /ce reminded me that it >would sometimes be useful to be able to 'initialise' xxcopy's >previous errorlevel to 0. > >I have one particular task in which I use a fairly complex batch >which carries out several checks on the passed parameters before >carrying out a single xxcopy using those parameters. To make the use >of the batch easy, this complex batch is called several times with a >simple batch containing a list of parameters. Something along the >lines of: > >:: Parent batch file >xxcopy /cb0 \\initialise xxcopy error to 0 >call mybackup src1 dest >call mybackup src2 dest >call mybackup src3 dest > >:: Mybackup batch file >:: Do error checking, parameter checking, rotate logs if necessary, >:: write logs, etc. >xxcopy /cb ... \\do the xxcopy work using passed parameters >:: Check for and log errors >:: Return to parent > >I currently handle this with 'if errorlevel' checks at the start of >the batch and by manipulating the errorlevel at the end of the batch >depending on the xxcopy error. It would be useful to simply 'set >xxcopy_error=0' prior to the first call to the xxcopy batch so >that /cb could then be specified. > >Or is there already a way to set the xxcopy error to 0? > >Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.