CMD.EXE and ECHO are Broken and fixed.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

CMD.EXE and ECHO are Broken and fixed.

#1 Post by alan_b » 15 Jul 2011 05:36

I was using DOS before there were Windows of any sort.
The rules are not what I remember.

Has your CMD.EXE changed, or will it change ?
This test script will find out.

Code: Select all

@echo off
echo       #
echo      ###
echo     #####
pause

Before I knew better I would have said the display would have 3 lines each starting with a hash, but what I now see is

Code: Select all

      #
     ###
    #####
Press any key to continue . . .


This change will break any code that depends upon the output of echo excluding all initial spaces,
but may be convenient where it obviates all the "work-arounds" that have been devised under "ECHO. FAILS to give text or blank line - Instead use ECHO/"
viewtopic.php?f=3&t=774

I am always suspicious of Patch Tuesday and "Out of band" Microsoft Updates ;
Additional possibilities include :-
Changing from 32 bit Laptop to 64 bit Desktop ;
Changing from XP Home + SP3 to Windows 7 Ultimate + SP1

I see the good, but fear the unknown.
Every time Microsoft patch something they always provide a way of attempting to uninstall because they often get it wrong;
what are they chances that some new whizz kid has made his mark on undocumented 30 year old source code to fix this ECHO and caused unfortunate side-effects which are waiting to ambush the users ?

College of CMD.EXE Gurus, your starter for 10 :-
What else got broken in CMD.EXE when ECHO was changed

Alan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CMD.EXE and ECHO are Broken and fixed.

#2 Post by aGerman » 15 Jul 2011 16:09

Well, the cmd is not the only thing they changed :lol:
How ever. Let's talk about cmd and a 2nd issue (that could fix the first).

You know that SET /P would display text as well. Here you will find the opposite effect.

Code: Select all

<nul set /p "=   #"&echo(

Preceding spaces are displayed in XP, but trimmed in Win7.

BTW As far as I remember ECHO didn't trim inital spaces in XP :?

Regards
aGerman

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: CMD.EXE and ECHO are Broken and fixed.

#3 Post by alan_b » 16 Jul 2011 02:32

I am sorry, 5 months of trying to use the Windows 7 GUI has obviously been damaging my memory faster than my medication can repair the damage ! !

After I initially started the topic on blank line creation with "ECHO." there was much discussion and various alternatives.
I have since tended to use "ECHO(" where a plain "ECHO" would not do what I want.
I now associate "ECHO( text" as a way of controlling the start position of text.

Last week I ran a BAT script that I previously used several years ago,
and was surprised to see an indentation on one line of an output table.
This was due to an extra space character after "ECHO" and before the text.
I am sure I would have removed that redundant character had I seen the indented line when using it under XP,
hence I deduced that XP trimmed all leading white space but Win 7 only skipped the first space.

If I ever finish fighting with Win 7 I will pull XP out of mothballs and investigate further.

Thanks
Regards
Alan

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

Re: CMD.EXE and ECHO are Broken and fixed.

#4 Post by dbenham » 16 Jul 2011 06:16

I have confirmed that ECHO on XP preserves leading spaces. I have a vague memory of ECHO in pre-Windows DOS stripping leading spaces unless ECHO. was used. But I haven't a machine to test on.

alan_b wrote:I now associate "ECHO( text" as a way of controlling the start position of text.
Not necessary for controlling start of text...
...but STILL very necessary for echoing a blank line :!: (unless Windows 7 has some new feature I am not aware of - I'm stuck on Vista)

ECHO( is not needed if there is subsequent text, unless the text is in a variable and there is a chance the variable is undefined.

Dave Benham

Post Reply