我在批处理文件中关闭了回显。
@echo off
然后我做了这样的事情
...
echo %INSTALL_PATH%
if exist %INSTALL_PATH%(
echo 222
...
)
我得到了:
系统找不到指定的路径。
这两个回显之间的消息是什么?
这个消息的原因是什么,为什么消息会忽略echo off?
我在批处理文件中关闭了回显。
@echo off
然后我做了这样的事情
...
echo %INSTALL_PATH%
if exist %INSTALL_PATH%(
echo 222
...
)
我得到了:
系统找不到指定的路径。
这两个回显之间的消息是什么?
这个消息的原因是什么,为什么消息会忽略echo off?
正如Mike Nakis所说,echo off
仅阻止命令的输出,而不是结果。 要隐藏命令的结果,请在行尾添加>nul
,要隐藏错误,请添加2>nul
。例如:
Del /Q *.tmp >nul 2>nul
就像Krister Andersson所说的那样,你之所以会出现错误是因为你的变量扩展了空格:
set INSTALL_PATH=C:\My App\Installer
if exist %INSTALL_PATH% (
成为:if exist C:\My App\Installer (
这意味着:
如果"C:\My"存在,则使用"("作为命令行参数运行"App\Installer"。
你看到此错误是因为没有名为"App"的文件夹。在路径周围加上引号以防止拆分。
将此保存为*.bat文件并查看差异
:: 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
"echo off"并没有被忽略。它表示您不想回显命令,但并未说明命令产生的错误。
您展示的这些行看起来没问题,所以问题可能不在此处。因此,请展示更多行。同时,请展示INSTALL_PATH的确切值。
"@echo off
// quote the path or else it won't work if there are spaces in the path
SET INSTALL_PATH="c:\\etc etc\\test";
if exist %INSTALL_PATH% (
//
echo 222;
)
IF EXIST“%INSTALL_PATH%”
。 - aphoriaC:\etc etc\test
。 - aphoria
if exist "%INSTALL_PATH%" (...
。 - Alex K.@echo off
只是意味着不应该将任何命令回显到终端。 - Cyclonecode