Solved How to compare data in a file?

December 1, 2011 at 08:39:00
Specs: Windows 7, 2933 Mhz 8Gb
What i am trying to do is gather the status of a certain set of processes that are running. I have already used batch commands to output the content to a file as per below.

From Example :

InProgress
InProgress
InProgress
Complete
Complete
InProgress

What i want to be able to do is to parse the file and decide that the script is complete if all the status's are "InProgress" or "Complete" and then goto the next step. The script needs to loop until one of the conditions is met.


How do i achieve this with batch commands?

Thanks in advance !


See More: How to compare data in a file?

Report •

#1
December 1, 2011 at 09:27:15
@echo off
:LOOP
for /F %%j in ('type "Status_File" ^| find /V /I "InProgress" ^| find /V /I "Complete"') do goto :LOOP


Report •

#2
December 1, 2011 at 12:23:00
HI IVO,

I have a series of programmes that are running and while i wait X time for their completion the status of the commands will change from InProgress to Complete over time.

From Example, if i have 3 programmes running, i am able to extract their current status to be :

InProgress
Complete
InProgress

What i what to be able to do is to continously pole the above data from a generated file and when all the lines read "Complete" then i want to exit and go to another phase of my script.

Complete
Complete
Complete

So what would be the best way to actively pole the output until it shows the status i require.I want to read each line and check to see if its the correct status (Complete), if not then go back and regenerate the file, check again etc until they eventually all show Complete


Thanks for reply so far!!


Report •

#3
December 1, 2011 at 14:46:20
✔ Best Answer
Your post was unclear thought I supposed you want to check for "Complete" only. Put the statement to create your status file where marked by Italics and you will exit the loop when the file holds "Complete" as the only strings.

@echo off
:LOOP
ping 1.0.0.0 -n 1 -w 4000 > nul
.........
HERE GENERATE YOUR Status_File
.........
for /F %%j in ('type "Status_File" ^| find /V /I "Complete"') do goto :LOOP
.........
HERE YOUR NEXT PHASE
......

I suggest you insert a delay in the loop to avoid overcharging the CPU by coding the ping command (tune the delay in msecs, e.g. 4000 = 4 secs).

Report •

Related Solutions

#4
December 2, 2011 at 04:03:38
This did exactly what i was looking for ! Thanks alot !!!!

Report •

Ask Question