Acabo de tropezar con algo extraño con % ERRORLEVEL% y quería ver si alguien sabe por qué y si hay una manera de solucionarlo. Básicamente, parece como si los comandos ejecutados dentro de sentencias if no configuraran la variable % ERRORLEVEL%. El ERRORLEVEL (como en IF ERRORLEVEL 1, que es diferente de IF% ERRORLEVEL% EQU 1) cheque parece todavía funcionan muy bien sin embargo, así que probablemente puede evitar, pero todavía sería agradable estar capaz de imprimir el nivel de error. Para la depuración o lo que sea.ERRORLEVEL adentro IF
@echo off
Set TESTVAR=1
tasklist | find /I "IsntRunning.exe" > NUL
echo OUTSIDE_IF %ERRORLEVEL%
ThisWillSetErrorLevelTo9009ieNotRecognizedCommand
tasklist | find /I "IsntRunning.exe" > NUL
echo OUTSIDE_IF %ERRORLEVEL%
ThisWillSetErrorLevelTo9009ieNotRecognizedCommand
IF %TESTVAR% EQU 1 (
Set ERRORLEVEL=
tasklist | find /I "IsntRunning.exe" > NUL
echo INSIDE_IF ERRORLEVEL %ERRORLEVEL%
IF ERRORLEVEL 1 (
echo INSIDE_IF2 ERRORLEVEL GREQ 1 %ERRORLEVEL%
)
IF ERRORLEVEL 2 (
echo INSIDE_IF2 ERRORLEVEL GREQ 2 %ERRORLEVEL%
)
IF ERRORLEVEL 3 (
echo INSIDE_IF2 ERRORLEVEL GREQ 3 %ERRORLEVEL%
)
)
tasklist | find /I "IsntRunning.exe" > NUL
echo OUTSIDE_IF ERRORLEVEL %ERRORLEVEL%
@echo on
Poniendo eso en un archivo por lotes y en funcionamiento que produce esta salida:
C:\Users\username\Documents\work>test.bat
OUTSIDE_IF 1
'ThisWillSetErrorLevelTo9009ieNotRecognizedCommand' is not recognized as an internal or external command,
operable program or batch file.
OUTSIDE_IF 1
'ThisWillSetErrorLevelTo9009ieNotRecognizedCommand' is not recognized as an internal or external command,
operable program or batch file.
INSIDE_IF ERRORLEVEL 9009
INSIDE_IF2 ERRORLEVEL GREQ 1 9009
OUTSIDE_IF ERRORLEVEL 1
artículos pertinentes:
- http://blogs.msdn.com/b/oldnewthing/archive/2008/09/26/8965755.aspx
- http://support.microsoft.com/kb/69576
Lo siento, he perdido su enlace –