简体   繁体   English

BATCH 检查txt文件是否包含字符串并执行批处理

[英]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.我想我想仅当 txt 文件中存在特定字符串时才继续运行批处理。

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...我找不到正确的方法来做到这一点......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM