Everyone knows, that in Windows command file (.cmd
)
echo on
echo off
enables and disables echo. But how to echo only text "on" or text "off"? I.e. how to send text
on
off
to stdout
?
Target system: Windows XP.
And what about making it in DOS?
The ECHO-ON and ECHO-OFF commands are used to enable and disable the echoing, or displaying on the screen, of characters entered at the keyboard. If echoing is disabled, input will not appear on the terminal screen as it is typed. By default, echoing is enabled.
To display the command prompt, type echo on. If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command.
Example# @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.
That means that every command issued in a batch file (and all of its output) would be echoed to the screen. By issuing, the 'echo off' command, this feature is turned off but as a result of issuing that command, the command itself will still show up on the screen.
C:\> echo.on
on
C:\> echo.off
off
This actually works with a number of different characters, including but possibly not limited to:
/
, \
, ,
, :
, ;
, (
.
According to this thread on dostips.com, it's actually best (most robust) to use:
echo(on
As the other characters have obscure situations in which they can fail (e.g. a file named echo
exists on %PATH%
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With