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

标签 windows batch-file cmd text-files

我想仅当 txt 文件中存在特定字符串时才继续运行批处理。

示例:

setlocal ENABLEDELAYEDEXPANSION

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

但我不想创建文件。

我找不到正确的方法......

最佳答案

很难准确说出您在问什么,因为您已经在运行批处理文件,所以如何不运行批处理文件来确定是否应该运行批处理文件?

无论如何,我会看看这是否对您有帮助:

@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

关于windows - BATCH 检查txt文件是否包含字符串并执行批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58593946/

相关文章:

windows - Perl: "start perl.exe <filename>"与 "perl.exe <filename>"有何不同

windows - 如何通过 Windows 上的命令行检查 https 页面上的字符串是否可用?

windows - 删除除一个目录外的所有文件和目录

windows - 符合此条件的 Windows 文本编辑器是什么

Windows 批处理文件时间比较

windows - 根据批处理文件中的第二个变量调用变量

windows - 如何将以 "!"结尾的参数传递给另一个bat文件?

windows - 在Windows 7上启动cassandra错误系统找不到指定的路径

c++ - 在 Desktop Duplication API 中获取的帧之间的 CPU 使用率高,超时间隔不同

file - 如何将计时器添加到批处理文件中?