I have an exe program, which generates a plain text output file.
In this output there is among other text one specific word indicating, when the program is finished (or close enough to finish for my purpose), and some word of a second category, which indicates the result of program and can be one of about 16 different words.
I would like to automatically start the program repeatedly and keep a count of which end result happened how often.
Describing what the batch should do is therefore rather easy:
stringf=finishword, string1=wordresult1...string16=wordresult16, nbrrun=(how often i want the program to be run), boolfinishvar=0, result1=0...result16=0
for i=1 to (how many runs i want to have) {
booldfinishvar=0
....exe
while boolfinishvar=0 do (if !(find stringf in "....txt") do (
boolfinishvar=1
if (find string1 in "...txt") do result1+=1
...
if (find string16 in "...txt") do result16+=1
)
)
}
echo %result1% ... %result16%
I mainly have no idea about the syntax for if !(find stringf in "....txt") or if (find string1 in "...txt").
And somehow commands regarding variables in the do part of if are sometimes ignored for unknown reasons, e.g. if whatever do command1 varable+=1 command2 , then commands 1 and 2 are done, but the variable is not changed.
Any suggestions appreciated.
repeatedly starting exe file and counting specific words
Moderator: DosItHelp
Re: repeatedly starting exe file and counting specific words
just to understand the problem right, you have a "file", and you need to search in this file for:
> One specific word ---> That indicate you reached the desired result or close to it.
> 16 specific words ---> That you need to search for them and keep track of how may times they appear int the file.
The batch start the EXE a set of times you specify, and after each start and after the processing of that output file is done, you want a total result of all that.
is that right ?
and about
did you enabled the delayed expansion like this:
and use !var! instead of %var% after that command
> One specific word ---> That indicate you reached the desired result or close to it.
> 16 specific words ---> That you need to search for them and keep track of how may times they appear int the file.
The batch start the EXE a set of times you specify, and after each start and after the processing of that output file is done, you want a total result of all that.
is that right ?
and about
then commands 1 and 2 are done, but the variable is not changed.
did you enabled the delayed expansion like this:
Code: Select all
Setlocal EnableDelayedExpansion
and use !var! instead of %var% after that command
Re: repeatedly starting exe file and counting specific words
abc0502 wrote:just to understand the problem right, you have a "file", and you need to search in this file for:
> One specific word ---> That indicate you reached the desired result or close to it.
> 16 specific words ---> That you need to search for them and keep track of how may times they appear int the file.
The batch start the EXE a set of times you specify, and after each start and after the processing of that output file is done, you want a total result of all that.
is that right ?
yes
Re: repeatedly starting exe file and counting specific words
This EXE App, Does it overwrite the output file each time it work? or you have to delete it first before you run this app again ?
The batch is almost finished just need the answer for the above question and,
How do you want the result to be shown?
> directly on the screen and after you press any key each time you get a new report.
OR
> output the result to files named like this report1.txt, report2.txt, etc. "something like that" [ depending on how many times you are going to run the exe ]
OR
> both
The batch is almost finished just need the answer for the above question and,
How do you want the result to be shown?
> directly on the screen and after you press any key each time you get a new report.
OR
> output the result to files named like this report1.txt, report2.txt, etc. "something like that" [ depending on how many times you are going to run the exe ]
OR
> both
Re: repeatedly starting exe file and counting specific words
abc0502 wrote:This EXE App, Does it overwrite the output file each time it work? or you have to delete it first before you run this app again ?
overwrite.
abc0502 wrote:The batch is almost finished just need the answer for the above question and,
Thanks!
abc0502 wrote:How do you want the result to be shown?
> directly on the screen and after you press any key each time you get a new report.
OR
> output the result to files named like this report1.txt, report2.txt, etc. "something like that" [ depending on how many times you are going to run the exe ]
OR
> both
output in file, though one file for all runs is best, as the desired result is just a list of 16 numbers, showing how often which exe result was generated.
Re: repeatedly starting exe file and counting specific words
carn wrote:I have an exe program, which generates a plain text output file.
In this output there is among other text one specific word indicating, when the program is finished (or close enough to finish for my purpose), and some word of a second category, which indicates the result of program and can be one of about 16 different words.
I would like to automatically start the program repeatedly and keep a count of which end result happened how often.
What words are they? Do we let the program run to completion or do you want to kill the task?
Showing us the format of the file would help to. Put it in code tags to preserve spaces.
I'm not sure how abc0502 planned his code without knowing these things...
Re: repeatedly starting exe file and counting specific words
You will Create 2 Files:
1> W1.set --> that will hold the SINGLE word that tell you you are finished or close to.
2> W16.set --> that will hold a list of all your 16 words you will search for. "each word in separate line"
The above names can be any other names put make sure you change it's names in the batch "lines 10 & 12"
This is the Code:
The report file will contain the word and how many times it appeared.
Though, I'm not sure if calling the function will <line 17> will wait till the exe finish and then call it again, but if it didn't work, the code can be all combined in one big for loop "i hope
"
Also, note that you will have to set the variables in lines 7 to 15, with the prober data.
I'm assuming you know the name of the plain text file that is generated, you will have to provide it's name.
One more thing, when you try a new run for the exe make sure you delete the old report file first or it will just append to it.
1> W1.set --> that will hold the SINGLE word that tell you you are finished or close to.
2> W16.set --> that will hold a list of all your 16 words you will search for. "each word in separate line"
The above names can be any other names put make sure you change it's names in the batch "lines 10 & 12"
This is the Code:
Code: Select all
@Echo OFF
Color 0A
Mode 40,10
Title Report
Setlocal EnableDelayedExpansion
:: file is the name of the txt file the EXE generate.
Set "file=file.txt"
:: W1 is the file that will hold the word that indicates the successful finish.
Set "W1=W1.set"
:: W16 is the file that will hold a list of 16 words you will search for.
Set "W16=W16.set"
:: num is how many times you will run the EXE file.
Set "num=5"
:: time is how many seconds the EXE file take to generate the txt file
Set "time=3"
For /L %%A in (1,1,%num%) Do Call :Process "%file%" "%W1%" "%W16%" "%%A" "%time%"
Echo.&Echo.&Echo.&Echo.&Echo All Done !
pause >nul
Exit /B
:Process
:: Start the EXE Program.
:: << Write here the application name between double quotes >>
:: This is how many seconds the exe application take to generate the file.
Ping localhost -n %~5 >nul
:: Search for the 1 word that indecate success.
Set Count1=0
For /F "delims=" %%@ in ('TYPE "%~2"') Do (
Set "StringF=%%@"
For /F "delims=" %%a in ('FINDstr /I /C:"%%@" "%~1"') Do (
Set /A Count1 += 1
)
)
Set "StringF_c=!Count1!"
:: Search for the 16 words.
Set Count2=0
Set sup1=1
Set sup2=0
For /F "delims=" %%@ in ('TYPE "%~3"') Do (
set "String!sup1!=%%@"
set /a sup1 += 1
For /F "delims=" %%a in ('FINDstr /I /C:"%%@" "%~1"') Do (
Set /A Count2 += 1
)
Set /A sup2 += 1
Set "String!sup2!_c=!Count2!"
Set Count2=0
)
:: Generate Report
:: StringF --> StringF_c
:: StringX --> StringX_c
(
Echo.
Echo ========================
Echo Report No# ^<%~4^>
Echo ========================
Echo.
Echo OutPut File : %~1
Echo.
Echo Fin String : [!StringF_c!] -- !StringF!
Echo.
Echo 1st String : [!String1_c!] -- !String1!
Echo 2nd String : [!String2_c!] -- !String2!
Echo 3rd String : [!String3_c!] -- !String3!
Echo 4th String : [!String4_c!] -- !String4!
Echo 5th String : [!String5_c!] -- !String5!
Echo 6th String : [!String6_c!] -- !String6!
Echo 7th String : [!String7_c!] -- !String7!
Echo 8th String : [!String8_c!] -- !String8!
Echo 9th String : [!String9_c!] -- !String9!
Echo 10th String : [!String10_c!] -- !String10!
Echo 11th String : [!String11_c!] -- !String11!
Echo 12th String : [!String12_c!] -- !String12!
Echo 13th String : [!String13_c!] -- !String13!
Echo 14th String : [!String14_c!] -- !String14!
Echo 15th String : [!String15_c!] -- !String15!
Echo 16th String : [!String16_c!] -- !String16!
Echo ========================
)>>"Report.txt"
Goto :EOF
The report file will contain the word and how many times it appeared.
Though, I'm not sure if calling the function will <line 17> will wait till the exe finish and then call it again, but if it didn't work, the code can be all combined in one big for loop "i hope

Also, note that you will have to set the variables in lines 7 to 15, with the prober data.
I'm assuming you know the name of the plain text file that is generated, you will have to provide it's name.
One more thing, when you try a new run for the exe make sure you delete the old report file first or it will just append to it.