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 18542 times)

0 Members and 1 Guest are viewing this topic.

Jaka

  • Guest
number of times started
« on: November 03, 2014, 01:25:42 PM »
Hi.
Can someone here helpe with batc which will start program file1.exe and file2.exe
After starts file1.exe it will write 1 to txt file.
after it will start file1.exe second time it will write 2 to txt file.
And when it will start third time file1.exe it will write 3 to txt file and so on until it will write 5 to txt file. Than it stop to starting file1.exe.
But this file also need to check before it start file1.exe if there is number 5 in txt file it will not start file1.exe but it will start file2.exe
and it will not start file1.exe until file2.exe is started 3 times. So it will work the same as file1.exe, it will write in some other txt file 1 when it start file2.exe first time and than it will write 2 into txt when starts second time and 3 when it is started third time. After that it must erase first txt file with number 5 to zero and second txt with number 3 to zero and start all over again with starting file1.exe. So batch will write 2 txt files for each program it will start.
Is that possible with batch flle?

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: number of times started
« Reply #1 on: November 03, 2014, 03:40:41 PM »
So you want a log file something like this:

File1
1
2
3
4
5
File2
1
2
3

Please explain exactly what this is and what is is for.  This will ensure a more accurate answer.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #2 on: November 03, 2014, 05:01:08 PM »
I am not sure I understand the point of this. Batch is sequential processing. I am not sure writing to a log file is really relavant for what you are trying to accomplish.

Jaka

  • Guest
Re: number of times started
« Reply #3 on: November 04, 2014, 05:21:45 AM »
point is that batch file will run exe file which check backup and if backup is missing it will restart program for backup
when program is stared 5 times than it should restart PC and when PC is restarted than goes to backup program and when that cycle with restarting comes to 3 times it will stop all.

But yes you have reminded me for some important thing. on 5 times file1.exe goes 1 time file2.exe
order should be
5 times file1.exe
than stop
than 1 time file2.exe
than stop
and go again to file1.exe
when file1.exe 5 times
than stop
than file2.exe
than stop
than again 5 times file1.exe
than stop
than file2.exe
than stop finally


if that is possible with batch file and two txt files for log cycles
batch file is runned by task scheduler every hour. Number of first and second cycles will change if it will be needed, so thats why also need txt file to check how many times some cycle is needed.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: number of times started
« Reply #4 on: November 04, 2014, 06:29:05 AM »
point is that batch file will run exe file which check backup and if backup is missing it will restart program for backup
when program is stared 5 times than it should restart PC and when PC is restarted than goes to backup program and when that cycle with restarting comes to 3 times it will stop all.

But yes you have reminded me for some important thing. on 5 times file1.exe goes 1 time file2.exe
order should be
5 times file1.exe
than stop
than 1 time file2.exe
than stop
and go again to file1.exe
when file1.exe 5 times
than stop
than file2.exe
than stop
than again 5 times file1.exe
than stop
than file2.exe
than stop finally


if that is possible with batch file and two txt files for log cycles
batch file is runned by task scheduler every hour. Number of first and second cycles will change if it will be needed, so thats why also need txt file to check how many times some cycle is needed.
Failure to leave out important details usually leads to a script that doesn't work for your needs.  Provide as much detail as possible about what you are currently doing and what you need the final result to be.

Jaka

  • Guest
Re: number of times started
« Reply #5 on: November 04, 2014, 06:51:02 AM »
yes you are 100% right.
So I will make step by step what script should do. I hope this will be more clear what I need, if not please let me know.

1) Stating scritp
1. checking first txt file for number
2. if number is not 5 going to next line
3. starting file1.exe which check and makes backup
4. script write 1 to txt
5. script close

2) starting script again
1. checking first txt file for number
2. if number is not 5 going to next line
3. starting file1.exe which check and makes backup
4. script write 2 to txt
5. script close
....................................... ..... 5 times
5) starting script again
1. checking first txt file for number
2. if number is not 5 going to next line
3. starting file1.exe which check and makes backup
4. script write 5 to txt
5. script close

6) starting script again
1. checking first txt file for number
2. number is now 5 in txt file so it will not start file1.exe
3. but will go to second part of script and
4. check second txt file if there is not 3 in that file
5. it will start file2.exe
6. and write 1 in second txt file

after that it will go to 1) again

................................3 times

8 ) starting script again
1. checking first txt file for number
2. number is now 5 in txt file so it will not start file1.exe
3. but will go to second part of script and
4. check second txt file id there is 3 in that file
5. it will stop

script won't start again until I delete one or both txt files with number 5 or 3.

first part of script runs 5 times and than second part 1 time and than again first part 5 times and than second part 1 time and again frist part 5 times and second part 1 time and after that stops until one or both of txt files are deleted.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: number of times started
« Reply #6 on: November 04, 2014, 09:23:03 AM »
I think your looking for something like this:
Code: [Select]
For /l %%b in (1,1,3) do (
For /l %%a in (1,1,5) do (
Start file1.exe
Echo %%a >log1.log
)
Start file2.exe
Exho %%b >log2.log
)

Check the switches for start.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Blisk



    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    Re: number of times started
    « Reply #7 on: November 04, 2014, 09:59:14 AM »
    Lol, keyboard mess with me.
    This script I have already see somewhere I will post it if I find it.

    Jaka

    • Guest
    Re: number of times started
    « Reply #8 on: November 04, 2014, 11:52:00 AM »
    I think your looking for something like this:
    Code: [Select]
    For /l %%b in (1,1,3) do (
    For /l %%a in (1,1,5) do (
    Start file1.exe
    Echo %%a >log1.log
    )
    Start file2.exe
    Exho %%b >log2.log
    )

    Check the switches for start.

    Sorry this doesn't work.
    I tested it with notepad.exe and calc.exe
    And when I started script it has opened 15 notepads and 3 calcs.
    But it should open only one notepad when I start a script
    and second time when I start a script also just one notepad
    and third time also
    and fourth time also
    and fifth time it should not open notepad.exe but calc.exe
    and sixth time it should opend notepad.exe
    and seveth also notepad.exe
    and so on until 10th time
    than it should open calc.exe instead notepad.exe
    and 11th time should open notepad.exe
    and 12th time should also opened notepad.exe
    and 13th time also notepad.exe
    until 15th time than it should not opened notepad.exe but calc.exe
    and than when I start script nothing happend until I delete one or both txt file
    than it should start all over again.

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: number of times started
    « Reply #9 on: November 04, 2014, 01:55:56 PM »
    Lol, keyboard mess with me.
    This script I have already see somewhere I will post it if I find it.

    HuH ? ?
    " Anyone who goes to a psychiatrist should have his head examined. "

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: number of times started
    « Reply #10 on: November 04, 2014, 02:22:14 PM »
    I intentionally gave you a semi finctional program so you would learn how to do it yourself.  Reread my post.
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: number of times started
    « Reply #11 on: November 04, 2014, 03:09:48 PM »
    I think I understand what you are doing now and why the log file is needed. Will see if I can get something written up tomorrow but I know it is already tomorrow some where down under.

    Jaka

    • Guest
    Re: number of times started
    « Reply #12 on: November 05, 2014, 12:23:59 AM »
    I intentionally gave you a semi finctional program so you would learn how to do it yourself.  Reread my post.
    thank you, but I think you expect too much from me. I am really lame for this.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: number of times started
    « Reply #13 on: November 05, 2014, 02:23:22 AM »
    You want to run file1.exe five times, and then file2.exe just one time, and loop?

    Code: [Select]
    @echo off
    :loop
    for %%a in (1 2 3 4 5) do "file1.exe"
    "file2.exe"
    goto :loop


    This expects your programs to close by themselves once they have finished. 
    If they don't close by themselves, then how will me know when to close them?



    Jaka

    • Guest
    Re: number of times started
    « Reply #14 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. 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