Batch ERRORLEVEL results different from CMD?
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
Why does ERRORLEVEL behave differently in these two circumstances?
From the command line:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>aescrypt.exe -v 2> NUL
C:\>echo %errorlevel%
9009
Versus from batch file:
@echo off
set /P C="> "?
set or=
if "%C%"=="a" set or=1
if "%C%"=="A" set or=1
if defined or (
aescrypt.exe -v 2> NUL
echo %errorlevel%
)
Result:
> a
1
This question and answers originated from www.stackoverflow.com
Question by wes (10/14/2010 6:53:14 PM)
Answer |
Remove you "@echo off" and see how the code is being executed. You might find that the errorlevel in example 2 is the result of the "if defined".
Also, try this:
@echo off
set /P C="> "?
set or=
if /i "%C%"=="a" set or=1
if not defined or goto SKIP
aescrypt.exe -v 2> NUL
echo %errorlevel%
:SKIP
Answer by Simon Catlin
Find More Answers
Related Topics batch errorlevel