Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 690
Enrico Mangani Avatar asked Nov 30 '25 07:11

Enrico Mangani


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
like image 179
avery_larry Avatar answered Dec 04 '25 01:12

avery_larry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!