[英]Find a word in a text file and assign it to a variable in windows batch
我正在嘗試以 60 秒的間隔在 txt 文件中搜索一個單詞(因為 txt 文件的內容會隨時間而變化),如果找到該單詞,搜索將停止並執行一些代碼。 我用下面的代碼來找到這個詞,但我不知道如何將它分配給一個變量。
>nul find "SUCCESS" C:\usr\new.txt && (
echo OK
) || (
echo FAILED
)
謝謝你。
為了實現目標,你真正需要的是一個保持循環、超時和 findstr,使用成功的結果來打破循環。
@Echo Off
rem // define and qualify search file path
Set "Searchee=%~1"
If not exist "%Searchee%" (Echo/File not located & Exit /B)
rem // holding loop
:Hold
(Type "%Searchee%" | (Findstr /L "SUCCESS")) >Nul 2> Nul && Goto :Act
Timeout 60 >Nul
Goto :Hold
:Act
Echo/String Located
rem // insert commands to be enacted
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.