我在bat文件中关闭了echo。
@echo off
然后我做了这样的事
...
echo %INSTALL_PATH%
if exist %INSTALL_PATH%(
echo 222
...
)
我得到了:
系统找不到指定的路径。
这两个回声之间的信息。
产生这条消息的原因是什么?为什么消息忽略回显?
发布于 2012-01-11 14:13:49
正如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:\
”,请使用"(“作为命令行参数)运行"App\Installer”。
您会看到错误,因为您没有名为"App“的文件夹。在路径周围放置引号以防止这种分裂。
发布于 2016-05-26 05:23:27
将其保存为*.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
发布于 2012-01-11 09:24:04
“回声关闭”不被忽略。“回显关闭”意味着您不希望这些命令回显,它没有提到任何由命令产生的错误。
你给我们看的台词看上去不错,所以问题可能不在那里。所以请给我们看更多的台词。另外,请告诉我们INSTALL_PATH的确切值。
https://stackoverflow.com/questions/8823643
复制相似问题