Echo off but messages are displayed

后端 未结 5 1817
梦谈多话
梦谈多话 2021-01-30 15:40

I turned off echo in bat file.

@echo off

then I do something like this

...
echo %INSTALL_PATH%
if exist %INSTALL_PATH%(
echo 22         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 16:30

    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.

提交回复
热议问题