I turned off echo in bat file.
@echo off
then I do something like this
... echo %INSTALL_PATH% if exist %INSTALL_PATH%( echo 222 ... )
and I get:
The system cannot find the path specified.
message between those two echos.
What can be the reason of this message and why message ignores echo off?
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.
echo off. When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: @echo off.
By default, each command in a batch file is echoed to the screen as it is executed. Echo on and echo off toggles this feature. To turn echoing off without displaying the echo off command, use @echo off. The @ symbol in front of any command in a batch file prevents the line from being displayed.
As Mike Nakis said, echo off
only prevents the printing of commands, not results. To hide the result of a command add >nul
to the end of the line, and to hide errors add 2>nul
. For example:
Del /Q *.tmp >nul 2>nul
Like Krister Andersson said, the reason you get an error is your variable is expanding with spaces:
set INSTALL_PATH=C:\My App\Installer if exist %INSTALL_PATH% (
Becomes:
if exist C:\My App\Installer (
Which means:
If "C:\My" exists, run "App\Installer" with "(" as the command line argument.
You see the error because you have no folder named "App". Put quotes around the path to prevent this splitting.
Save this as *.bat file and see differences
:: print echo command and its output echo 1 :: does not print echo command just its output @echo 2 :: print dir command but not its output dir > null :: does not print dir command nor its output @dir c:\ > null :: does not print echo (and all other commands) but print its output @echo off echo 3 @echo on REM this comment will appear in console if 'echo off' was not set @set /p pressedKey=Press any key to exit
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