![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject[>>] [<<]Thread[>>]
Number : 3832 Date : 2003-02-24 Author : Garry Deane Subject : Re: Errorlevel is not the same as an exit code. Size(KB) : 3
--- In xxcopy@yahoogroups.com, Kan Yabumoto wrote: > I have worked on this issue quite a bit. It was very > frustrating. But, the "SET" command (a built-in command > within the command processor (COMMAND.COM or CMD.EXE) > uses its "backdoor" mechanism to let the parent process > (the command processor) to change the value. That is, > as far as I know, there is no straightforward method > to emulate what the SET command does by a regular program > like XXCOPY. If you know the answer, please let me > see the source code. It will be extremely useful. I don't have any source code but there are many utilities that do this with both COMMAND.COM (putinenv.exe, winset, strings.com) and CMD.EXE (setx.exe, pathman.exe, conset.exe). For COMMAND.COM, I believe that the usual method to modify the parent environment is to use Int 2E with DS:SI pointing to a command string length followed by a command string and a CR such as 0x0f,'Set prompt= [$n]',0x0d. I don't know what calls are used for CMD.EXE but I believe it's a standard API call. The only problem is that due to the differences in the way the environment is managed, each method is incompatible with the other OS i.e. you can't use Int 2E with NT/W2k/XP and you can't use the Win32 API with W95/W98/ME. I suppose the above difficulties could be worked out but I don't see much point. Under NT/W2k/XP, the errorlevel is automatically set in the environment by CMD.EXE and can be accessed using %errorlevel% e.g. set xx_error=%errorlevel% Under W95/W98/ME, you can call a batch file to determine the errorlevel and put it in an environment variable or you can use a utility to parse the log file and extract the error code listed in the log file. Below is a cut down version of a batch file which sets the environment variable %errlvl% to the errorlevel returned by the preceding program (note that long lines will have wrapped). It is used like this: xxcopy * d:\test /y call errlvl.bat echo xxcopy errorlevel is %errlvl% Alternately, using a utility program such as LMOD (http://home.mnet- online.de/horst.muc/) to parse the log file is almost as straightforward. xxcopy *.tmp f:\test /y /onxxcopy.log find "Exit" ~seterr.bat for %%i in (call del) do %%i ~seterr.bat echo xxcopy errorlevel is %errlvl% Garry ::======== errlvl.bat ============== @ECHO OFF REM - SET ENVIRONMENT VARIABLE "ERRLVL" TO ERRORLEVEL K. MANOS 04-05-94 IF NOT [%ERRLVL%]==[] SET ERRLVL= IF NOT ERRORLEVEL 20 GOTO 0 IF NOT ERRORLEVEL 80 GOTO 60 IF NOT ERRORLEVEL 140 GOTO 120 IF NOT ERRORLEVEL 200 GOTO 180 :240 FOR %%V IN (240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255) DO IF ERRORLEVEL %%V SET ERRLVL=%%V IF NOT [%ERRLVL%]==[] GOTO EXIT : :Add intervening values for other errorlevels : :60 FOR %%V IN ( 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79) DO IF ERRORLEVEL %%V SET ERRLVL=%%V IF NOT [%ERRLVL%]==[] GOTO EXIT :40 FOR %%V IN ( 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59) DO IF ERRORLEVEL %%V SET ERRLVL=%%V IF NOT [%ERRLVL%]==[] GOTO EXIT :20 FOR %%V IN ( 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39) DO IF ERRORLEVEL %%V SET ERRLVL=%%V IF NOT [%ERRLVL%]==[] GOTO EXIT :0 FOR %%V IN ( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) DO IF ERRORLEVEL %%V SET ERRLVL=%%V IF NOT [%ERRLVL%]==[] GOTO EXIT :EXIT IF [%1]==[1] ECHO ** ERRLVL: ERRORLEVEL=%ERRLVL% IF [%1]==[2] ECHO ** ERRORLEVEL=%ERRLVL% ::======== end errlvl.bat ===========
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.