You are not logged in.

#1 08 Jul 2019 22:17

binki
Member
Registered: 08 Jul 2019
Posts: 2

ERRORLEVEL from SET differs in interactive mode

Hi,

I was unclear if this is the right place to post feedback about the docs. It seems maybe I was supposed to use the guestbook section of the forum, but this section is about the subject which I am actually giving feedback.

I noticed on nt/errorlevel.html that SET is documented as not affecting ERRORLEVEL. When playing with CMD interactively, this does indeed seem to be the case. However, when I write it in a batch file, it seems to reset ERRORLEVEL. I think the documentation should be updated to explain this behavior.

For example, at a prompt:

C:\Users\ohnob>sjfklsdjflksjdflkjsd
'sjfklsdjflksjdflkjsd' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\ohnob>SET x=%ERRORLEVEL%

C:\Users\ohnob>IF ERRORLEVEL 1 ECHO errorlevel1
errorlevel1

If I have a script, though:

C:\Users\ohnob>TYPE AppData\Local\Temp\sldfjlskdfj.cmd
@ECHO OFF
sdlkfjsdlkfsklfjsld
SET x=%ERRORLEVEL%
IF ERRORLEVEL 1 ECHO errorlevel1 0
ECHO %ERRORLEVEL%, %x%

C:\Users\ohnob>CALL AppData\Local\Temp\sldfjlskdfj.cmd
'sdlkfjsdlkfsklfjsld' is not recognized as an internal or external command,
operable program or batch file.
0, 9009

Please let me know if there’s anything I can do to help with updating the documentation. Please also point out to me if I missed something.

I am wondering about the other commands in the “Commands that do NOT affect the ERRORLEVEL:” list too. Haven’t spent time investigating their behavior.

Thanks!

Offline

#2 09 Jul 2019 19:01

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: ERRORLEVEL from SET differs in interactive mode

Good spot, I have tested that and updated the page now.

People tend to post suggestions in this thread:  » meta  » Pages in ss64.com/nt/ that need update
but it doesnt really matter, also we should probably setup a separate thread for PowerShell suggestions.

Thanks and welcome to the forum!

Offline

#3 09 Jul 2019 19:55

binki
Member
Registered: 08 Jul 2019
Posts: 2

Re: ERRORLEVEL from SET differs in interactive mode

Thanks for responding, updating, and going beyond and actually researching the issue more fully!

I looked and was a bit confused at the change at first, but now I see that this is a .cmd versus .bat thing. Interesting!

Your website is a valuable resource which I have used in the recent years and found very helpful. Thanks again!

Offline

#4 10 Jul 2019 03:52

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: ERRORLEVEL from SET differs in interactive mode

Perhaps you may be interested in this topic that explain the %errorlevel% value in a more extensive way...

Antonio

Offline

#5 10 Jul 2019 19:24

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: ERRORLEVEL from SET differs in interactive mode

I have rewritten a couple of parts of the errorlevel page again today to make things a bit clearer - it is a confusing topic.

I've also linked to Antonios helpful SO answer and will probably add some of those exit codes to the individual pages if they arent already there.

Offline

Board footer

Powered by