BATCH Check if a txt file contains a string and execute the batch

Viewed 1229

I would like to I would like to continue running the batch only if a specific string exists in a txt file.

Example:

setlocal ENABLEDELAYEDEXPANSION

if....
Findstr "check_ok" "C:\tmp\test.txt"
( 
     ...continue...
) ELSE (
exit
)

but I don't want to create a file.

I can't find the correct way to do it...

1 Answers

Hard to tell exactly what you're asking, because you're already running the batch file so how do you not run the batch file to find out if you should run the batch file?

Regardless, I'm going to see if this helps you:

@echo off
setlocal enabledelayedexpansion

:: Check for "check_ok" and exit the batch file if it is NOT found
Findstr -m /S /C:"check_ok" "C:\tmp\test.txt" || goto :eof

:: If we get here, then check_ok was found
:: Continue with the rest of your batch file
Related