添加暂停后,cmd仍会关闭

时间:2016-08-10 03:46:58

标签: batch-file

我想编写一个小批处理文件来搜索目录中多个文本文件中的文本,并在搜索后立即关闭。所以,我用谷歌搜索,我遇到的最常见的答案是添加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

1 个答案:

答案 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