Page 1 of 1
Why do people exit /b instead of goto :eof
Posted: 19 May 2011 18:32
by Ed Dyreen
I presume its faster
Re: Why do people exit /b instead of goto :eof
Posted: 19 May 2011 19:44
by dbenham
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
Re: Why do people exit /b instead of goto :eof
Posted: 19 May 2011 19:53
by Ed Dyreen
advantage ? Then I will have to start using it
exit /b 0
Re: Why do people exit /b instead of goto :eof
Posted: 20 May 2011 05:32
by orange_batch
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%