I am using 2 batch files that are calling each other and i don't want them to stop until i do it manually.
My issue is that when they start running, they are calling each other for approximately 2 hours.
Batch file 1(power_failure.bat):
python c:\alex_folder\UPS_SCRIPTS\TURN_OFF_FOR_BAT.py >>c:\alex_folder\UPS_SCRIPTS\log.txt
TIMEOUT /T 20 /NOBREAK >nul
call power_ok.bat
Batch file 2(power_ok.bat):
python c:\alex_folder\UPS_SCRIPTS\TURN_ON_FOR_BAT.py >>c:\alex_folder\UPS_SCRIPTS\log.txt
TIMEOUT /T 20 /NOBREAK >nul
call power_failure.bat
What can be changed in order for these scripts to run for ever until i stop them and not only 2 hours?
Related
I want to know the batch script to be included in my present batch script to schedule it for every 30 minutes.
myscript.bat
#echo off
java -jar myscript.jar
If you are asking how to loop the script with a 30 minute timeout between execution of java, then:
#echo off
:start
java -jar myscript.jar
timeout /t 1800 /nobreak >nul 2>&1
goto :start
if you wanted to actually schedule it to run every 30 minutes, then use your task scheduler.
This question already has answers here:
How to wait in a batch script? [duplicate]
(6 answers)
How to sleep for five seconds in a batch file/cmd [duplicate]
(30 answers)
Closed 6 years ago.
I have the below script but it does not sleep before executing the software.
Any ideas?
#echo off
SLEEP 10
START "" "C:\Program Files (x86)\..."
There are (at least) the following options, as others already stated:
To use the timeout command:
rem // Allow a key-press to abort the wait; `/T` can be omitted:
timeout /T 5
timeout 5
rem // Do not allow a key-press to abort the wait:
timeout /T 5 /NOBREAK
rem // Suppress the message `Waiting for ? seconds, press a key to continue ...`:
timeout /T 5 /NOBREAK > nul
Caveats:
timeout actually counts second multiples, therefore the wait time is actually something from 4 to 5 seconds. This is particularly annoying and disturbing for short wait times.
You cannot use timeout in a block of code whose input is redirected, because it aborts immediately, throwing the error message ERROR: Input redirection is not supported, exiting the process immediately.. Hence timeout /T 5 < nul fails.
To use the ping command:
rem /* The IP address 127.0.0.1 (home) always exists;
rem the standard ping interval is 1 second; so you need to do
rem one more ping attempt than you want intervals to elapse: */
ping 127.0.0.1 -n 6 > nul
This is the only reliable way to guarantee the minimum wait time. Redirection is no problem.
Try the timeout command.
timeout /t 10
This shows Waiting for 10 seconds, press a key to continue ...
You can use the /nobreak switch that ignores user input (other than CTRL-C)
timeout /t 30 /nobreak
Or you can redirect its output to NUL for a blank screen that waits 10 seconds and ignores user input:
timeout /t 30 /nobreak > NUL
#call JBOSSbuildWar.bat > ..\logs\JBOSSbuildWar_out 2> ..\logs\JBOSSbuildWar_err
start cmd /c #call WeblogicbuildWar.bat > ..\logs\WeblogicbuildWar_out 2> ..\logs\WeblogicbuildWar_err
start cmd /c #call FEBAPortletWebWar.bat > ..\logs\FEBAPortletWebWar_out 2> ..\logs\FEBAPortletWebWar_err
start cmd /c #call buildStaticJBoss.bat > ..\logs\JBOSSFEBAStaticWar_out 2> ..\logs\JBOSSFEBAStaticWar_err
I have this set of batch files getting executed in order. I want to fork out this so that they execute in parallel. I have done that using start cmd /c. Now this will fork out new command prompt window for each of them. Assume there are some set of statements after this. I want to make sure they get executed only after all the forked batch files are finished. How to achieve this?
Lets say average time taken by each file is:
JBOSSbuildWar- 30 minutes
WeblogicbuildWar- 35 minutes
FEBAPortletWebWar- 30 minutes
buildStaticJBoss- 35 minutes
Since the main command prompt window has completed its task in 30 minutes, and the forked batch files needs another 5 minutes to complete, I want the main cmd to wait until the others are done. Kindly help.
there's multiple commands, you can choose what one to use,
Pause
Will pause cmd until the user presses any key.
Displays message, "Press any key to continue..."
I use a certain variation of this command called pause>nul.
What it does is pauses the .bat, but doesn't show a message, You just get a blank screen!
TIMEOUT
Multiple syntaxes, very useful command, use this one quite a bit.
Sample code: TIMEOUT 10
Can be bypassed by a key press
Pauses the execution of command by 10 seconds.
You can also structure it like this: TIMEOUT 10 /nobreak
Which does not allow the user to press a key to skip it, they must endure it!
Ping
Very nice one.
Syntax is like this: PING 1.1.1.1 -n 1 -w 60000 >NUL
Probably most complex of the three.
PING can be used to delay execution for a number of seconds.
Hope I helped!
-Logan
Easy way:
In your main batch,
del "%temp%\*.processfinished" >nul 2>nul
...
start ....whatever1.bat...
start ....whatever2.bat...
start ....whatever3.bat...
...
wait4all:
for /L %%a in (1,1,3) do if not exist "%temp%\%%a.processfinished" timeout /t 1 >nul &goto wait4all
:: continues here when all (3) processes have finished.
del "%temp%\*.processfinished" >nul 2>nul
Then in each of the (3) subsidiary .bat files, create a file "%temp%\x.processfinished" where x=1 for the first process, 2 for the second and so on.
When the sub-processes have started, the procedure waits until each has created its own ".processcompleted" file by checking whether any of the 3 is missing, if it it, timeout for 1 second and look again. Only if the 3 files are present will it continue.
In all probability, it would be best if the subsidiary processes could take an extra parameter (the name of this sub-process's "processfinished" file) rather than having a fixed number for each.
You could extend this, and use say the date and time to augment the filename so that this entire process could itself be run many times in parallel.
BTW - by starting the procedure with
#echo off
you can remove all of the leading #s (all that does is suppress the command-reporting for that one line.)
Also, start is happier as start "" ....., that is, with an empty window title in quotes as its first argument. This allows other arguments to be "quoted" as necessary - the very first "quoted" argument used is used as the "window title" for the process and is likely to be lost to the sub-process. Routinely assigning a dummy (empty if necessary) "window title" means you don't trip over this problem in the future.
You can add this timer function before each of the commands:
#call JBOSSbuildWar.bat > ..\logs\JBOSSbuildWar_out 2> ..\logs\JBOSSbuildWar_err
Timeout /t 60 /nobreak >nul
start cmd /c #call WeblogicbuildWar.bat > ..\logs\WeblogicbuildWar_out 2> ..\logs\WeblogicbuildWar_err
Timeout /t 60 /nobreak >nul
start cmd /c #call FEBAPortletWebWar.bat > ..\logs\FEBAPortletWebWar_out 2> ..\logs\FEBAPortletWebWar_err
Timeout /t 60 /nobreak >nul
start cmd /c #call buildStaticJBoss.bat > ..\logs\JBOSSFEBAStaticWar_out 2> ..\logs\JBOSSFEBAStaticWar_err
Ps: 60 stands for 1 minute, if you want 30 minutes, change it to 1800
I am attempting to start recording the screen using Camtasia however am triggering this using a batch file.
As i need the recordings to be 30 seconds long, i have a secondary batch file. It doesn't work as intended as i would like to avoid multiple windows executing the commands opening. I know the command taskkill isn't correct and have included it to illustrate what i am intending to achieve.
The batch files need to be able to run on both Windows 7 and Windows 8 devices.
The process is started with a starting batch file that launches the secondary batch file to commence the countdown.
StartFile.bat
start EndFile.bat
"C:\Program Files\TechSmith\Camtasia Studio 8\CamRecorder.exe" /record
EndFile.bat
timeout /T 30 /NOBREAK
"C:\Program Files\TechSmith\Camtasia Studio 8\CamRecorder.exe" /stop
timeout /T 30 /NOBREAK
taskkill /f /im StartFile.bat <-- To kill the first batch file so there aren't multiple windows
start StartFile.bat <-- To create a new instance of the starting batch file.
exit
Just do it all in a single batch file with a GOTO loop (edited to take account of the discussion in the comments; the start is only needed because starting recording doesn't return control):
:startofloop
start "" "C:\Program Files\TechSmith\Camtasia Studio 8\CamRecorder.exe" /record
timeout /T 30 /NOBREAK
"C:\Program Files\TechSmith\Camtasia Studio 8\CamRecorder.exe" /stop
timeout /T 30 /NOBREAK
goto startofloop
I have a doStuff.bat script with this command :
"%HOME%\bin\groovy.bat" "%HOME%\bin\DoSth.groovy"
What can i do to get that command run every 5 minute without using Window Task Schedule?
The timeout command in modern windows will pause for 5 minutes/300 seconds.
#echo off
set "home=c:\home folder"
:loop
call "%HOME%\bin\groovy.bat" "%HOME%\bin\DoSth.groovy"
timeout 300
goto :loop