0

Error running and killing then run another batch file on specific time period. Tried to run timeout and CALL simultaneously but I guess there's an error in my lines so it doesnt go through. Since my .bat file wouldn't finish itself once it ran I can't just put timeout on another line under it. Tried using | but it also won't do it

@echo off
set /a maxLoop=999999
set /a loopCount=%maxLoop%
for /l %%x in (1, 1, %maxLoop%) do (
   CALL c:\rclone\rclone1.bat | timeout 21600
   wmic process where name="rclone1.exe" call terminate > nul
   CALL c:\rclone\rclone2.bat | timeout 21600
   wmic process where name="rclone2.exe" call terminate > nul
   CALL c:\rclone\rclone3.bat | timeout 21600
   wmic process where name="rclone3.exe" call terminate > nul
   CALL c:\rclone\rclone4.bat | timeout 21600
   wmic process where name="rclone4.exe" call terminate > nul
   set /a loopCount=%loopCount%-1
   if "%loopCount%"=="0" GOTO :EOF
)

2 Answers 2

0

You have to escape the pipe inside the for and you forgot the /t switch ex:

CALL c:\rclone\rclone1.bat ^| timeout /t 21600

  • I'm on Windows 11 and not putting the /t switch seems to work anyway but I'm not sure about other Windows versions...

Also you started a *.bat file but you are finishing an *.exe ????

@echo off
set /a maxLoop=999999
set /a loopCount=%maxLoop%
for /l %%x in (1, 1, %maxLoop%) do (
                                    CALL c:\rclone\rclone1.bat
                                    timeout /t 21600 >nul
                                    wmic process where name="rclone1.exe" call terminate > nul
                                    CALL c:\rclone\rclone2.bat
                                    timeout /t 21600 >nul
                                    wmic process where name="rclone2.exe" call terminate > nul 
                                    CALL c:\rclone\rclone3.bat
                                    timeout /t 21600 >nul
                                    wmic process where name="rclone3.exe" call terminate > nul
                                    CALL c:\rclone\rclone4.bat
                                    timeout /t 21600 >nul
                                    wmic process where name="rclone4.exe" call terminate > nul
                                   )
4
  • im on Windows 10, inside that .bat it runs .exe
    – dawnslayer
    Commented Apr 16, 2022 at 13:25
  • The batch files actually starts exe files? Commented Apr 16, 2022 at 13:54
  • the final files to be started by .bat are .exe
    – dawnslayer
    Commented Apr 16, 2022 at 15:44
  • So does the example that I posted in the answer work? Commented Apr 16, 2022 at 15:49
0

Just try to invert the commands using pipe:

// replace

command | timeout 

// per

timeout | command

@echo off

set /a maxLoop=999999
set /a loopCount=%maxLoop%

for /l %%x in (1, 1, %maxLoop%) do (
     timeout 21600 | call c:\rclone\rclone1.bat  
     wmic process where name="rclone1.exe" call terminate >nul
     timeout 21600 | call c:\rclone\rclone2.bat
     wmic process where name="rclone2.exe" call terminate >nul
     timeout 21600 | call c:\rclone\rclone3.bat
     wmic process where name="rclone3.exe" call terminate >nul
     timeout 21600 | call c:\rclone\rclone4.bat
     wmic process where name="rclone4.exe" call terminate >nul
     set /a loopCount=%loopCount%-1
     if "%loopCount%"=="0" GOTO :EOF
   )

To prevent the output strings of the timeout command redirected in the console after the execution of the called bat is finished from appearing on the console screen, use >nul 2>&1:

@echo off

set /a maxLoop=999999
set /a loopCount=%maxLoop%

for /l %%x in (1, 1, %maxLoop%) do (
     >nul 2>&1 timeout 21600 | call c:\rclone\rclone1.bat  
     wmic process where name="rclone1.exe" call terminate >nul
     >nul 2>&1 timeout 21600 | call c:\rclone\rclone2.bat
     wmic process where name="rclone2.exe" call terminate >nul
     >nul 2>&1 timeout 21600 | call c:\rclone\rclone3.bat
     wmic process where name="rclone3.exe" call terminate >nul
     >nul 2>&1 timeout 21600 | call c:\rclone\rclone4.bat
     wmic process where name="rclone4.exe" call terminate >nul
     set /a loopCount=%loopCount%-1
     if "%loopCount%"=="0" GOTO :EOF
   )

What I would do in an equality scenario and without using variables, but using my personal preferences, the code would be:


@echo off

for /l %%i in =;(999999, -000001, 000001)do @for /l %%y in =;(01, 01, 04)do =;(
     >nul 2>&1 timeout 21600 | start /b "" cmd.exe /r "c:\rclone\rclone%%y.bat"
     <con: call wmic process where name="rclone%%y.exe" call terminate >nul );=

If the intention is to wait for the call + timeout command to complete and only after that you need to force the rcloneX.exe executable to terminate, I would try to use:

@echo off

for /l %%i in =;(999999, -000001, 000001)do @for /l %%y in =;(01, 01, 04)do =;(
     cmd.exe /v /q /r ">nul 2>&1 timeout.exe 2160 | "c:\rclone\rclone%%~y.bat""
     <con: call wmic process where name="rclone%%y.exe" call terminate >nul );=

2
  • the intention is to terminate rclone1 after it ran for 21600 seconds then run rclone2 and so on
    – dawnslayer
    Commented Apr 17, 2022 at 2:48
  • try the last code...
    – Io-oI
    Commented Apr 17, 2022 at 2:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .