1.

Solve : number of times started?

Answer»

Quote from: Jaka on November 05, 2014, 02:30:51 AM

Program will close itself when it finishes backup - file1.exe
and file2.exe also because it is for reboot.

The batch file is not going to keep running in a loop if a reboot happens.

Quote
This script is not started that often, so program have no time to close, but it is started with TASK schedule every hour.
file1.exe loop 5 times and than goes to file2.exe and than again loop 5 times and than goes to file2.exe.
but that happend only when I start batch(task scheduler), not by itself, like this script which opens 15 file1.exe and 3 file2.exe.
it should open only ONE file1.exe

You said EARLIER that you tested it with notepad. There will be multiple copies of notepad open, and this is the expected behaviour, do you know why?
Quote from: foxidrive on November 05, 2014, 09:10:48 AM
The batch file is not going to keep running in a loop if a reboot happens.
I think this is why he said we need to keep track of the number of times it has ran in a log file.Quote from: Squashman on November 05, 2014, 09:12:44 AM
I think this is why he said we need to keep track of the number of times it has ran in a log file.
yes, that is it.
every time I start batch it will write log in txt file for example for notepad
and also everytime after that is stared calc.exe it will write log in second txt file
so script knows what to do nex time I start it.Quote from: Squashman on November 05, 2014, 09:12:44 AM
I think this is why he said we need to keep track of the number of times it has ran in a log file.

I read the first two explanations and then my eyes glazed over.



See if this is what you are looking for. I must have missed when you said that you were rebooting between each execution.

Code: [Select]
@echo off
setlocal EnableDelayedExpansion
if exist log1.log set /p t1=<log1.log
if not defined t1 set t1=1
if %t1% LEQ 5 (
file1.exe
set /a t1+=1
echo !t1! >log1.log
) else (
if exist log1.log set /p t2=<log2.log
if not defined t2 set t2=1
if !t2! LEQ 3 (
file2.exe
set /a t2+=1
echo !t2! >log2.log
))


EDIT: Missed a close parenthesis at the end, was fixed.Quote from: foxidrive on November 05, 2014, 09:45:42 AM
I read the first two explanations and then my eyes glazed over.
I am sorry if this is to complicated and to hard to do.Might want to fix that.
Code: [Select]if exist log1.log set /p t2=<log2.logQuote from: Jaka on November 05, 2014, 11:00:50 AM
I am sorry if this is to complicated and to hard to do.
The only hard part is getting the user to explain what EXACTLY they want to do and the information we need to code it.Quote from: Lemonilla on November 05, 2014, 11:00:25 AM
See if this is what you are looking for. I must have missed when you said that you were rebooting between each execution.

Code: [Select]
@echo off
setlocal EnableDelayedExpansion
if exist log1.log set /p t1=<log1.log
if not defined t1 set t1=1
if %t1% LEQ 5 (
file1.exe
set /a t1+=1
echo !t1! >log1.log
) else (
if exist log1.log set /p t2=<log2.log
if not defined t2 set t2=1
if !t2! LEQ 3 (
file2.exe
set /a t2+=1
echo !t2! >log2.log
))


EDIT: Missed a close parenthesis at the end, was fixed.

YAY this almost work.
I tested again with notepad and calc.

And it opens 5 times notepad and than opens 3 times calc.
This is almost it

But it should open 5 times notepad and than 1 time calc and than goes again to notepad 5 times and than again 1 calc and than goes again 5 times to notepad and again 1 time calc and stop.Quote from: Squashman on November 05, 2014, 11:23:54 AM
The only hard part is getting the user to explain what exactly they want to do and the information we need to code it.
yes I know, but I am trying to explain really hard how this should work. I know one single thing and script doesn't work right.Try harder...either on your work...or the explanation of what
you want to do...So let us get this straight.

Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 1 to log2.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 2 to log2.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 3 to log2.txt

Lather, rinse, repeat..........
Quote from: Squashman on November 05, 2014, 02:15:41 PM
So let us get this straight.

Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 1 to log2.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 2 to log2.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 1 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 2 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 3 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 4 to log1.txt
Your scheduled task will fire.
The batch file will run file1.exe and write 5 to log1.txt
Your scheduled task will fire.
The batch file will run file2.exe and write 3 to log2.txt

Lather, rinse, repeat..........

yes exactly that
and when I delete log1.txt or log2.txt or both
than it will start all over again from start

Now I see how I should explain what script sould do. Sorry for my bad explanation.
This your is really great, now I will know for next time. Today I learned something more.
Hmmm,
Not sure about your logic with deleting one file or both. What happens when you delete log1.txt and log2.txt has a value of 3. The way I would understand your logic is that file1.exe would run 5 times and file2.exe will never run. Is that correct?No logic...and i just THOUGHT about the overall goal of this project...i came up with HuH ? ?


Discussion

No Comment Found