Create *.bat file?

0 like 0 dislike
11 views
Tell me how to do the test in the file:

I have a file xxx.log larger than 10 MB. at the very end should be the string "Everything is Ok" how to check this string if it is then execute the command-if not then exit the script.


OS: Windows
by | 11 views

7 Answers

0 like 0 dislike
$lastline = gc xxx.log | select -last 1
if ($lastline eq "Everything is Ok") {write-host Wheee!}
\r
PowerShell
by
0 like 0 dislike
Can't resist :) GREP's, PowerShell's — unsportsmanlike.
Slow version using pure batch:
\r
for /f "delims=" %%a in (build.xml) do set lastLine="%%a" if %lastLine%=="Everything is Ok" echo YEAH! 

However, will work only under some Windows older than XP.
by
0 like 0 dislike
Maybe it's better to do it with PowerShell?
by
0 like 0 dislike
I think you will help variable %ERRORLEVEL%
If the file is found the desired combination, the variable will return "0" otherwise "1".
\r
For example:
find "Everything is Ok" if %ERRORLEVEL%==1 start start.cmd
if %ERRORLEVEL%==1 pause
\r
If the line is there, run start.cmd, if the line is not there, the script will wait for pressing any key.
by
0 like 0 dislike
Slashes in the file path beguiled )
\r
@echo off findstr "Everything is Ok" d:/test.txt >null if errorlevel 1 GOTO EXIT :COMMAND echo echo "Whoooohoo!" EXIT exit 0 
by
0 like 0 dislike
findstr "Everything is Ok" c:\\path\\to\\logfile.log
by
0 like 0 dislike
@echo off for /F %%I in ('"find /n /i "everything is ok" file.txt | cut-f 1 -d ] | cut-f 2 -d ["') do SET Number=%%I 2>nul For /F "Tokens=3" %%A In ('Find /V /C "" file.txt') Do Set sCount=%%A If %sCount% GEQ %Number% Echo whoohoo 

\r
something like this. grep is acarapi, the utility cut can be taken from cygwin, for example
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
7 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
4 answers
110,608 questions
257,186 answers
0 comments
28,647 users