what's going on with 2 new lines at the end of a bat?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
taripo
Posts: 228
Joined: 01 Aug 2011 13:48

what's going on with 2 new lines at the end of a bat?

#1 Post by taripo » 23 Nov 2011 07:41

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?

paultomasi
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?

#2 Post by paultomasi » 25 Nov 2011 20:58

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'.

taripo
Posts: 228
Joined: 01 Aug 2011 13:48

Re: what's going on with 2 new lines at the end of a bat?

#3 Post by taripo » 25 Nov 2011 21:25

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.

paultomasi
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?

#4 Post by paultomasi » 25 Nov 2011 22:43

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.

taripo
Posts: 228
Joined: 01 Aug 2011 13:48

Re: what's going on with 2 new lines at the end of a bat?

#5 Post by taripo » 25 Nov 2011 23:54

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.

paultomasi
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?

#6 Post by paultomasi » 26 Nov 2011 00:18

Yes, GOTO :EOF exits a batch file at that point even if the label :EOF is present and followed by other commands.

Post Reply