1

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 loop

open 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 loop

does anyone know if this is even possible?

askedJul 23, 2016 at 16:31
ed sheeran's user avatar
7
  • There is thetimeout command to do the sleep;CommentedJul 23, 2016 at 16:47
  • With "close" you mean killing the related task? if so you need a way to identify the correct process (bytasklist command), get its PID and use that for thetaskkill command; one way is to specify a unique window title (bytitle command) and to search for that usingtasklist /V andfind/findstr...CommentedJul 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 fileCommentedJul 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...CommentedJul 23, 2016 at 17:45
  • 1
    SeeRe-opening files in Batch for some hintsCommentedJul 23, 2016 at 20:39

1 Answer1

1
start "RunBat" /d "C:\users\ivan\desktop\folder1" call run.bat

startsrun.bat in a new window with the titleRunBat with the working directoryC:\users\ivan\desktop\folder1 (no need for acd command)

timeout /t 1800 >nul

pauses 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.

answeredJul 24, 2016 at 16:24
Stephan's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.