Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#1
Post
by miskox » 08 Nov 2016 13:37
How to display (echo) words OFF and ON on the screen?
Of course these don't work:
Result:
Maybe this one (because echo. is used to display empty line):
Result:
Of course we can use
Anyone knows what was Microsoft's official way of doing this?
Saso
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#2
Post
by penpen » 08 Nov 2016 14:08
miskox wrote:Anyone knows what was Microsoft's official way of doing this?
The last recommendation Microsoft gave (that i know) is for "MS-DOS 6.22":
But under "MS-DOS 6.22" "echo" was a reserved command (so the CLI doesn't search for "echo.bat").
Nowadays i prefer to use "echo(", but also this depends on the string you want to print.
For more information see:
http://www.dostips.com/forum/viewtopic.php?t=1900penpen
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#3
Post
by dbenham » 09 Nov 2016 05:46
penpen wrote:Nowadays i prefer to use "echo(", but also this depends on the string you want to print.
I'm not aware of any strings where ECHO( fails to work.
Dave Benham
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#4
Post
by ShadowThief » 09 Nov 2016 06:40
dbenham wrote:penpen wrote:Nowadays i prefer to use "echo(", but also this depends on the string you want to print.
I'm not aware of any strings where ECHO( fails to work.
Dave Benham
I thought we decided somewhere that echo/ worked better for printing blank lines for some reason, but I could be remembering it wrong.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#5
Post
by penpen » 09 Nov 2016 07:43
dbenham wrote:I'm not aware of any strings where ECHO( fails to work.
Actually i cannot remember the exact string, and it only happens when using "call echo" (EDIT: If i remember right that string exits the cmd.exe - but i cannot find the example - could have sworn that this string was posted to this forum... .).
If there is a file existing called echo.bat/.exe/... (ext in {%pathext%}), then it may also fail.
If you use a file "echo.bat":
When using "call" this happens:
Code: Select all
Z:\>call echo(abc
"Z:\echo.bat" # (abc
Z:\>call echo:abc
abc
Z:\>call echo/abc
abc
penpen
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#6
Post
by dbenham » 09 Nov 2016 15:29
Aaaarrgghh
I had never seen the CALL ECHO( case before - and it is horrific news. That means there does not exist a universal form of ECHO that can be used in all circumstances.
The goal is to be able to do something like ECHO(!VAR!, where VAR may be undefined, or contain absolutely any string, and the command should always work, regardless of context.
Jeb's analysis shows that there is at least one scenario where every character fails except for (
But now the CALL problem eliminates our last hope. The
problems with "macros", and :: comments within blocks are both obscure and easy to avoid, so I was not concerned. But CALL ECHO( is another story. As much as I like to avoid CALL, I can see where it might be highly desirable on occasion.
Dave Benham
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#7
Post
by jeb » 11 Nov 2016 06:52
penpen wrote:Actually i cannot remember the exact string, and it only happens when using "call echo" (EDIT: If i remember right that string exits the cmd.exe - but i cannot find the example - could have sworn that this string was posted to this forum... .).
If there is a file existing called echo.bat/.exe/... (ext in {%pathext%}), then it may also fail.
Proof of fail
Code: Select all
echo echo FAIL > echo.bat
call echo( this fails
call echo^( this fails too
I suppose the "call echo(" problem is known for a while, but it doesn't hurt too much, as CALL <anyCommand> has always the problem that <anyCommand> will be searched on the disk.
It's always necessary to use "set pathExt=." for a secure CALL usage.
Code: Select all
@echo off
echo echo FAIL > echo.bat
setlocal
set pathext=.
call echo( this works
call echo^( this works too
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#8
Post
by dbenham » 11 Nov 2016 08:40
Thanks jeb. Perfectly logical - I just never thought to apply the knowlege to CALL ECHO before.
The solution sounds like a good candidate for a %@callEcho% macro
Dave Benham