Running 2 or more programs sequentially and iteratively
Moderator: DosItHelp
Running 2 or more programs sequentially and iteratively
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 ?
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 ?
Re: Running 2 or more programs sequentially and iteratively
Does this do what you want to do?
Code: Select all
@echo off
:loop
start "" /w "path\Program1"
start "" /w "path\Program2"
goto :loop
Re: Running 2 or more programs sequentially and iteratively
small modification
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
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
Re: Running 2 or more programs sequentially and iteratively
@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.
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.
Re: Running 2 or more programs sequentially and iteratively
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.
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.
Re: Running 2 or more programs sequentially and iteratively
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.....
Re: Running 2 or more programs sequentially and iteratively
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:My problem is both programs hit 100% CPU and stay there. They do a lot of processing till I force stop them.
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.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.....
Liviu
Re: Running 2 or more programs sequentially and iteratively
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.
Re: Running 2 or more programs sequentially and iteratively
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 correctif 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.