我想编写一个小批处理文件来搜索目录中多个文本文件中的文本,并在搜索后立即关闭。所以,我用谷歌搜索,我遇到的最常见的答案是添加pause
一些人也建议使用set /p=
或cmd
但是没有一个有效。我将pause
放在文件的错误区域吗?
@echo off
findstr /m "softban soft ban" *.txt > results.txt
if %errorlevel% == 0(
echo Found a match, logged file in results.txt
)else(
echo no matches found
)
pause
更新代码:
@echo off
findstr /m "softban soft ban" *.txt > results.txt
if %errorlevel% EQU 0 ( echo Found a match, logged file in results.txt )
if %errorlevel% NEQ 0 ( echo no matches found )
echo press any key to exit...
pause >nul
答案 0 :(得分:3)
在parantheses之间需要空格。试试这段代码。
@echo off
findstr /m "softban soft ban" *.txt > results.txt
IF %ERRORLEVEL%==0 (
echo Found a match, logged file in results.txt
) ELSE (
echo not found
)
pause