Running 2 or more programs sequentially and iteratively

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
K.A.T
Posts: 3
Joined: 13 Apr 2012 08:10

Running 2 or more programs sequentially and iteratively

#1 Post by K.A.T » 14 Apr 2012 15:20

Hello,

I would like to run to batch programs that run sequentially, as such each takes 30 min. CPU time then stops. The other programs starts for another 30. min then stops and the first runs again.....

i.e

path\Program1 ----- run for 30 min. or whatever time set...

stop or sleep

path\Program2 ---- run for 30 min. or whatever time set...

and loopt back to start.


How do I do this in Windows 7 CMD or Power shell ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Running 2 or more programs sequentially and iteratively

#2 Post by foxidrive » 15 Apr 2012 02:34

Does this do what you want to do?

Code: Select all

@echo off
:loop
start "" /w "path\Program1"
start "" /w "path\Program2"
goto :loop

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Running 2 or more programs sequentially and iteratively

#3 Post by abc0502 » 15 Apr 2012 05:17

small modification

Code: Select all

@echo off
cls
set program1=C:\program1.exe
set program2=C:\program2.exe
:loop
start "" /w "%program1%"
timeout /T 1800 /NOBREAK
taskkill /f /im program1.exe >nul
start "" /w "%Program2%"
timeout /T 1800 /NOBREAK
taskkill /f /im program2.exe >nul
goto :loop


to wait 30 min and then kill the brevious programand start the new one
get the programs process names from the taskmanager to use with the taskkill command &
change the path in the set commands

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Running 2 or more programs sequentially and iteratively

#4 Post by foxidrive » 15 Apr 2012 05:55

@abc0502

The /w in the start command will stop timeout.exe running until the program has finished. So there's an issue.

I'd like to hear if the OP really does want to force kill the process after 30 minutes, but your timeout.exe and taskkill command can be launched before the start command in a temporary batch file so they run concurrently.

Edit: Or just remove the /w I guess from the start command.

K.A.T
Posts: 3
Joined: 13 Apr 2012 08:10

Re: Running 2 or more programs sequentially and iteratively

#5 Post by K.A.T » 15 Apr 2012 13:31

Hello,

Thanks for your replies guys.

The trick didn't work. the first error says the command in the given path isn't found. I guess it is killed before being found by taskkill or something.

K.A.T
Posts: 3
Joined: 13 Apr 2012 08:10

Re: Running 2 or more programs sequentially and iteratively

#6 Post by K.A.T » 15 Apr 2012 13:35

My problem is both programs hit 100% CPU and stay there. They do a lot of processing till I force stop them. Since I only have one computer running both in parallel will degrade war performance for one application due to switching.... What I want is to divide say a period of 24 hours for example between the 2 applications by alternating automatically as stated above.....

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Running 2 or more programs sequentially and iteratively

#7 Post by Liviu » 15 Apr 2012 15:02

K.A.T wrote:My problem is both programs hit 100% CPU and stay there. They do a lot of processing till I force stop them.
And if you do force stop them, they'd be at some random point in the middle of that processing. Taskkill'ing risks file corruption and/or resource leaks.

K.A.T wrote:Since I only have one computer running both in parallel will degrade war performance for one application due to switching.... What I want is to divide say a period of 24 hours for example between the 2 applications by alternating automatically as stated above.....
You may consider PsSuspend (http://technet.microsoft.com/en-us/sysi ... s/bb897540), and "put to sleep" one of the processes while resuming the other each half hour.

Liviu

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Running 2 or more programs sequentially and iteratively

#8 Post by abc0502 » 17 Apr 2012 06:19

foxidrive wrote:@abc0502

The /w in the start command will stop timeout.exe running until the program has finished. So there's an issue.

I'd like to hear if the OP really does want to force kill the process after 30 minutes, but your timeout.exe and taskkill command can be launched before the start command in a temporary batch file so they run concurrently.

Edit: Or just remove the /w I guess from the start command.


i searched for the /w in command prompt but didn't find it but after u explained there is a "wait" command i use windows 7 so i guess it changed from xp to 7

he said he wan't it to run every 30 min so i added the taskkill and timeout but liviu opinion is correct
if you do force stop them, they'd be at some random point in the middle of that processing. Taskkill'ing risks file corruption and/or resource leaks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Running 2 or more programs sequentially and iteratively

#9 Post by foxidrive » 17 Apr 2012 07:43

abc0502 wrote:i searched for the /w in command prompt but didn't find it but after u explained there is a "wait" command i use windows 7 so i guess it changed from xp to 7


It is /wait in XP too but /w works.

The /wait command will wait for the program1.exe to finish before timeout.exe is launched.

In that case taskkill would not run until the program has run for 30 minutes and exited by itself, and then the timeout command runs for another 30 minutes

but liviu opinion is correct
if you do force stop them, they'd be at some random point in the middle of that processing. Taskkill'ing risks file corruption and/or resource leaks.


Very true. Forcing programs to close that have open files like a database, is a bad idea.

Post Reply