I have this batch file which opens 4 cmds and then goes to the correspondingfolder and executes some other bat files which then execute python scripts.I basically want to have this batch file
:loopstart cmd.exe /k "cd C:\users\ivan\desktop\folder1 & call run.bat"start cmd.exe /k "cd C:\users\ivan\desktop\folder2 & call run.bat"start cmd.exe /k "cd C:\users\ivan\desktop\folder3 & call run.bat"start cmd.exe /k "cd C:\users\ivan\desktop\folder4 & call run.bat"goto loopopen these 4 cmds and then wait about 30 minutes and close and open them again, so it would look something like this
:loopstart cmd.exe /k "..."sleep(1800000)exitgoto loopdoes anyone know if this is even possible?
- There is the
timeoutcommand to do the sleep;aschipfl– aschipfl2016-07-23 16:47:19 +00:00CommentedJul 23, 2016 at 16:47 - With "close" you mean killing the related task? if so you need a way to identify the correct process (by
tasklistcommand), get its PID and use that for thetaskkillcommand; one way is to specify a unique window title (bytitlecommand) and to search for that usingtasklist /Vandfind/findstr...aschipfl– aschipfl2016-07-23 16:55:00 +00:00CommentedJul 23, 2016 at 16:55 - @aschipfl I've got almost everything figured out but the problem is I can't use taskkill because the process PID will change every time I re-run the batch fileed sheeran– ed sheeran2016-07-23 17:01:56 +00:00CommentedJul 23, 2016 at 17:01
- That's why I was talking about the window title; you will need to get the PID for each loop iteration...aschipfl– aschipfl2016-07-23 17:45:55 +00:00CommentedJul 23, 2016 at 17:45
- 1SeeRe-opening files in Batch for some hintsDavidPostill– DavidPostill2016-07-23 20:39:12 +00:00CommentedJul 23, 2016 at 20:39
1 Answer1
start "RunBat" /d "C:\users\ivan\desktop\folder1" call run.batstartsrun.bat in a new window with the titleRunBat with the working directoryC:\users\ivan\desktop\folder1 (no need for acd command)
timeout /t 1800 >nulpauses the execution for (30min*60sec) 1800 seconds. (>nul: don't show the timer)
finally
taskkill /fi "WINDOWTITLE eq RunBat*"kills allcmd windows where the windowtitle starts withRunBat (this way you don't need the PIDs). (Give all your "daughter processes" the same title, so you can kill all of them with a singletaskkill command; or give them unique titles to be able to kill them separately)
Put a label and agoto around, and you're done.
Comments
Explore related questions
See similar questions with these tags.