Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: number of times started  (Read 18540 times)

0 Members and 1 Guest are viewing this topic.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: number of times started
« Reply #15 on: November 05, 2014, 09:10:48 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?

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #16 on: November 05, 2014, 09:12:44 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.

Jaka

  • Guest
Re: number of times started
« Reply #17 on: November 05, 2014, 09:34:03 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.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: number of times started
« Reply #18 on: November 05, 2014, 09:45:42 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.




Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: number of times started
« Reply #19 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.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Jaka

  • Guest
Re: number of times started
« Reply #20 on: November 05, 2014, 11:00:50 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.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #21 on: November 05, 2014, 11:22:13 AM »
Might want to fix that.
Code: [Select]
if exist log1.log set /p t2=<log2.log

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #22 on: November 05, 2014, 11:23:54 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.

Jaka

  • Guest
Re: number of times started
« Reply #23 on: November 05, 2014, 12:30:18 PM »
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.

Jaka

  • Guest
Re: number of times started
« Reply #24 on: November 05, 2014, 12:31:29 PM »
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.

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: number of times started
« Reply #25 on: November 05, 2014, 02:04:55 PM »
Try harder...either on your work...or the explanation of what
you want to do...
" Anyone who goes to a psychiatrist should have his head examined. "

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #26 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..........

Jaka

  • Guest
Re: number of times started
« Reply #27 on: November 05, 2014, 02:29:14 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.
 ;D

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #28 on: November 05, 2014, 02:44:35 PM »
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?

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: number of times started
« Reply #29 on: November 05, 2014, 02:53:54 PM »
No logic...and i just thought about the overall goal of this project...i came up with HuH ? ?
" Anyone who goes to a psychiatrist should have his head examined. "