回声关闭,但显示消息

回声关闭,但显示消息

问题描述:

我bat文件关闭回声。

I turned off echo in bat file.

@echo off

然后我做这样的事情。

then I do something like this

...
echo %INSTALL_PATH%
if exist %INSTALL_PATH%(
echo 222
...
)

和我得到的:

系统找不到指定的路径。

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?

Nakis说,回声关闭仅prevents命令,而不是结果的打印。若要隐藏命令的结果添加> NUL 到行的末尾,并隐藏错误添加 2 - ; NUL 。例如:

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% (

变成了:

if exist C:\My App\Installer (

这意味着:

如果C:\\我的存在,运行应用程序\\安装与(作为命令行参数

If "C:\My" exists, run "App\Installer" with "(" as the command line argument.

您看到的错误,因为你没有一个名为应用程序文件夹中。把引号的路径周围prevent这种分裂。

You see the error because you have no folder named "App". Put quotes around the path to prevent this splitting.