C:\>dir bloodyhell.bat
Volume in drive C has no label.
Volume Serial Number is FC9D-4769
Directory of C:\
11/23/2011 01:33 PM 0 bloodyhell.bat
1 File(s) 0 bytes
0 Dir(s) 13,415,006,208 bytes free
C:\>bloodyhell.bat
C:\>notepad bloodyhell.bat
C:\>bloodyhell.bat
C:\>
Look at the above, I have an empty file bloodyhell.bat
I execute it, it gives a gap and says C:\>
Fine.
I then open bloodyhell.bat and add 2 new lines to it.
Then I execute it, and it goes straight to C:\> with no gap.
It seems then, that there's a gap smaller than echo. that is outputted by default, after a bat file is run. Very neat.
That gap can be / is removed when ending a bat file with 2 blank new lines.
Has anybody encountered this before?
what's going on with 2 new lines at the end of a bat?
Moderator: DosItHelp
-
- Posts: 25
- Joined: 24 Feb 2009 14:52
- Location: UK
- Contact:
Re: what's going on with 2 new lines at the end of a bat?
Yep, I have come across this before.
A possible solution to this inconsistency is to add ':eof' as the last line of a batch file. It does not matter whether or not CR is pressed after ':eof'.
A possible solution to this inconsistency is to add ':eof' as the last line of a batch file. It does not matter whether or not CR is pressed after ':eof'.
Re: what's going on with 2 new lines at the end of a bat?
paultomasi wrote:Yep, I have come across this before.
A possible solution to this inconsistency is to add ':eof' as the last line of a batch file. It does not matter whether or not CR is pressed after ':eof'.
try pushing ENTER again so CRLFCRLF that's what causes it and the :EOF before that makes no difference to it.
-
- Posts: 25
- Joined: 24 Feb 2009 14:52
- Location: UK
- Contact:
Re: what's going on with 2 new lines at the end of a bat?
I was refering to suppressing additional linefeeds... Ideal when you don't want 'separating' linefeeds after commands.
By making your last line :eof (or any other label), whether that line is followed by other blank lines or not, DOS does not display a linefeed after the batch file ends (in XP anyway).
Exiting the batch file with EXIT (and it's variants) or GOTO :EOF, does however, and this apears to be consistent.
It's a matter of personal preference as to whether you want the linefeed or not.
By making your last line :eof (or any other label), whether that line is followed by other blank lines or not, DOS does not display a linefeed after the batch file ends (in XP anyway).
Exiting the batch file with EXIT (and it's variants) or GOTO :EOF, does however, and this apears to be consistent.
It's a matter of personal preference as to whether you want the linefeed or not.
Re: what's going on with 2 new lines at the end of a bat?
I see..
GOTO :EOF
or
EXIT
(no need for an :EOF label)
And no other label will do. And I see, the reason why :EOF works here, is because it Exits straight away.
Any lines after :EOF can exist, but will not run.
EXIT /B was easier to test.. I tested EXIT too, by putting it in a4.bat, doing a4.bat >z and reading z. And yep.
It must be that they work because they cause the interpreter to not read any further lines, so it won't hit on 2 or more CRLFs, even if they are there.
GOTO :EOF
or
EXIT
(no need for an :EOF label)
And no other label will do. And I see, the reason why :EOF works here, is because it Exits straight away.
Any lines after :EOF can exist, but will not run.
EXIT /B was easier to test.. I tested EXIT too, by putting it in a4.bat, doing a4.bat >z and reading z. And yep.
It must be that they work because they cause the interpreter to not read any further lines, so it won't hit on 2 or more CRLFs, even if they are there.
-
- Posts: 25
- Joined: 24 Feb 2009 14:52
- Location: UK
- Contact:
Re: what's going on with 2 new lines at the end of a bat?
Yes, GOTO :EOF exits a batch file at that point even if the label :EOF is present and followed by other commands.