Why do people exit /b instead of goto :eof

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Why do people exit /b instead of goto :eof

#1 Post by Ed Dyreen » 19 May 2011 18:32

I presume its faster :?:

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Why do people exit /b instead of goto :eof

#2 Post by dbenham » 19 May 2011 19:44

I have no idea about performance. I've always assumed it was a matter of personal preference.

I've always felt that exit /b looks more elegant. Goto :eof strikes me as kludgey or hackish, but I don't know of any compelling reason to use one over the other. I'm pretty sure goto :eof predates exit /b, so many people got used to using it before exit /b became available.

One advantage of exit /b is it allows you to set the errorlevel as in exit /b 23

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Why do people exit /b instead of goto :eof

#3 Post by Ed Dyreen » 19 May 2011 19:53

advantage ? Then I will have to start using it 8) exit /b 0

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Why do people exit /b instead of goto :eof

#4 Post by orange_batch » 20 May 2011 05:32

Same as dbenham said, but I don't care much for setting the errorlevel, except one trick.

First, if for some reason I need to reset the errorlevel to 0, use verify>nul. I didn't test the performance, but there's no way it's slower than cmd /c exit 0.

Second, a guy named carlos or something here posted some awesome tricks almost a year back.

You can easily convert any decimal to hexadecimal from 0 to FFFFFFFF by:
cmd /d /c exit 12345
echo Hex of 12345: %=exitcode%

Post Reply