enthuguy
asked on
how to get the word count within batch file in MS DOS and manipulate to exit loop
When I execute a command line execution. it returns an output like below.
task_name, description, 11, In_progress
task_name, description, 12, In_progress
task_name, description, 13, In_progress
task_name, description, 14, In_progress
task_name, description, 15, In_progress
task_name, description, 16, Finished
Would like to get help in
1. how to loop thru in MS Dos
2. how to get the count of "In_progress". In above case it is 5
3. My plan is to execute same script after regular interval and check the count. When it reached 0...meaning none in "In_progress" status.
4. exit the loop.
Thanks in advance
task_name, description, 11, In_progress
task_name, description, 12, In_progress
task_name, description, 13, In_progress
task_name, description, 14, In_progress
task_name, description, 15, In_progress
task_name, description, 16, Finished
Would like to get help in
1. how to loop thru in MS Dos
2. how to get the count of "In_progress". In above case it is 5
3. My plan is to execute same script after regular interval and check the count. When it reached 0...meaning none in "In_progress" status.
4. exit the loop.
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That should work indeed, but it is much better to use something like:
@echo off
:Loop
for /F %%C in ('find /c /i "in_progress" Temp.txt') do set Count=%%C
echo Current running instances %COUNT%
timeout /t 5
if %COUNT% gtr 0 goto Loop
echo No running instances, exiting
because you should never use aif ... goto
goto
sequence. That's the way we created simple programs in the early 80's.
I would simplify this to:
@echo off
setlocal
for /l %%i in (0,0,1) do (
rem Update log file here
find /i "in_progress" < "temp.txt" > NUL || goto :NoneFound
timeout /t 5
)
:NoneFound
~bp
Of course, we do not really need the count, so using a similar technique but without the FOR:
@echo off
:Loop
timeout /t 5
find /c /i "in_progress" Temp.txt >nul && goto Loop
echo No running instances, exiting
ASKER