I'm trying to create a .bat file to execute a flash video on a 10 s time interval in an infinite loop. So far I have...
ECHO OFF
:TOP
START /d "path" program.exe
SLEEP 10
TASKKILL /F /IM program.exe
GOTO TOP
It needs to restart the video after 10 seconds, but it just turns it on and that's it. Help!
Try this instead:
#echo off
:TOP
PathDir\program.exe
ping 127.0.0.1 -n 11
taskkill /im program.exe /f
goto :TOP
Haven't changed much but I haven't used SLEEP so not sure if that's causing the issue.
#echo off
#color 0a
:top
echo sleeping... sleeping...
sleep 5
goto top
echo waking... yargh!!! how dare yee wake thy neighbroseph?!
Also be sure to have this .bat file residing in the same directory as Sleep.exe which can be found: http://www.computerhope.com/dutil.htm
Tested and working exactly how I'd hoped.
Related
This can be two separate .bat files if needed, but I would prefer if it's possible on one.
I need to run a certain program, but it sometimes crashes.
I have this for a .bat so far.
It works as far as resetting the program every hour, but it does crash sometimes in between restarts.
I'd like to just have a check, so it launches if the program isn't found.
Is that possible?
#echo off
:loop
start "xx" "xxpath"
timeout /t 3600 >null
taskkill /f /im "xx" >null
timeout /t 4 >null
goto loop
Here is a sample batch that can check if any instance of chrome.exe is running or not
If not, we start it !
#echo off
Color 0A
Set WaitTimeSeconds=20
Set App_Path=C:\Program Files\Google\Chrome\Application\chrome.exe
for %%i in (%App_Path%) do set App_Name=%%~nxi
Title Checking if any "%App_Name%" instance is running ...
:Loop
Rem Clear the screen
cls
Rem Kill any application that have a status equal to not responding !
Taskkill /f /fi "status eq not responding">nul 2>&1
Rem Check if any application instance is running ; if not we start it !
TASKLIST | FINDSTR %App_Name% || START "" "%App_Path%"
Timeout /t %WaitTimeSeconds% /nobreak>nul
Goto Loop
I'm noobie in MS batch (bat). I need to save some streaming via VLC to file.
This script working greate for me:
#echo off
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "http://STREAM" --sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"}
But I need to stop recording after N seconds. So I think the best way is to get pid of this proccess and run
timeout /t 120 /nobreak
taskkill /t /pid %PID%
For this I found some solution:
#echo off
set "exe=C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
set "source=http://STREAM"
set "save-cmd=--sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"}"
for /f "tokens=2 delims==; " %%a in ('wmic process call create '"%exe%" "%source%" %save-cmd%' ^| find "ProcessId"') do set PID=%%a
echo "%PID%"
timeout /t 120 /nobreak
taskkill /t /pid %PID%
I'm getting PID, But VLC openning in normal way (don't do anything), as I just run C:\Program Files (x86)\VideoLAN\VLC\vlc.exe
How can I run programm with parameters and get PID of it?
Thanks!
According to the VLC forums, you can use --run-time and --stop-time parameters to close VLC after a specified amount of time.
For example adding --run-time 120 --stop-time=120 vlc://quit will exit after 2 hours
Updated script:
#echo off
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "http://STREAM" --sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"} --run-time 120 --stop-time=120 vlc://quit
I program to both learn how and to make fun files for jokes and tricks. I'm trying to make a batch file that will run a label inside the batch file for a set amount of time like 30 seconds without having to use a for-do statement. what I have so far is shown below and is reduced to a small test, but uses a for-do statement.
# echo off
for /l %%a in (1,1,10) do (
call :matrix)
echo Thanks for using the MATRIX
pause
:matrix
echo %random%%random%
use timeout command, it can set amount of time like 30 seconds without having to use a for-do statement.
# echo off
for /l %%a in (1,1,10) do (
call :matrix)
echo Thanks for using the MATRIX
timeout 30
:matrix
echo %random%%random%
if you don't want to show count done message, you can use timeout 30 >nul
this starts a second cmd process (minimized), that simply does a timeout 30. It's existence is the signal to repeat the loop.
#echo off
start /min "MyTimer" timeout 30
:loop
echo %random%%random%
tasklist /fi "windowtitle eq MyTimer" | find "Console" >nul && goto :loop
Sadly, tasklist doesn't give useful errorlevels, so we have to use find.
Note: for debugging purposes you may want to remove the start switch /min.
I am trying to work out how to run a batch file when a text file is created. I have tried to research but am unable to find anything that helps.
The Pseudocode of what I want is something like this:
When "Response.txt" is created run "2 Week.bat".
Thanks.
#echo off
:start_loop
if exist "c:\Response.txt" (
start cmd /c "c:\2weeks.bat"
goto :exodus
)
rem :: wait for 1 minute
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:60 >nul 2>&1
goto :start_loop
:exodus
This will work on Vista and later:
#echo off
:loop
if exist "c:\folder\Response.txt" "c:\folder\2 week.bat"
rem - reduce CPU usage by waiting for 15 seconds
timeout /t 15 /nobreak
goto :loop
I would like to start a program with a windows batch file. But the program should stop after a certain timeout value. For example: Run the program 60 seconds and stop it after 60 seconds.
Under Linux, there is this nice timeout command to do what I want. Windows has also a timeout command, but its just to pause a command, to delay its execution. Is there something else under Windows to do so ?
Setup: Windows 7, 64 Bit, Professional
start yourprogram.exe
timeout /t 60
taskkill /im yourprogram.exe /f
Bali C gave a concise and to the point answer.
I needed something a little more featureful and reusable.
Based on Bali C's Example. I came up with this.
If anyone should need the same as me.
your.bat
REM...
CALL STARTwaitKILL..bat /relative/path/your_program.exe
REM...
STARTwaitKILL.BAT
#ECHO OFF
IF[%1]==[] GOTO EOF
IF NOT EXIST %1 GOTO EOF
REM SET PRIORITY=/NORMAL
REM ADJUST PRIORITY, BELOWNORMAL LETS BATCH FILE RUN MORE SMOOTHLY
REM WITH A PROGRAM THAT CONSUMES MORE CPU. SEE ABOUT MAXWAIT BELLOW
SET PRIORITY=/BELOWNORMAL
REM SET PRIORITY=/LOW
REM 0 NORMAL WINDOW :: 1 NO WINDOW :: 2 MINIMIZED WINDOW
SET /A HIDDEN=1
REM MAXWAIT HERE IS MORE LIKE MINIMUM WAIT IN WINDOWS.
SET MAXWAIT=10
SET WAITCOUNT=0
SET ARGS=/I %PRIORITY%
IF %HIDDEN% EQU 1 SET ARGS=%ARGS% /B
IF %HIDDEN% EQU 2 SET ARGS=%ARGS% /MIN
START %ARGS% %1
:WAIT
IF %WAITCOUNT% GEQ %MAXWAIT% GOTO KILL_IT
TIMEOUT /T 1 > NUL
SET /A WAITCOUNT+=1
FOR /F "delims=" %%a IN ('TASKLIST ^| FIND /C "%~nx1"') DO IF %%a EQU 0 GOTO RUN_DONE
GOTO WAIT
:KILL_IT
TASKKILL /IM %~nx1 /F > NUL
:RUN_DONE
Could be fleshed out ore to take more arguments for priority and such, but I don't have the need for it. Shouldn't be hard to add.
Don't exist any command in Windows to delay an app or to set a timeout for an app
Timeout in Windows is for Delay the execution process of CMD/Batfile, nothing more utility.
You can use external tools for that, I don't remember the name of any now, so many underground software, sorry, but I remember that in the autoit official forum exists a similar commandline tool to launch an app setting the timeout,
and maybe in the tool NIRCMD, or ps2exec, check their help files, or someone inside the WAIK Kits.
This is the only you can do:
#Echo OFF
:: First launch the app in background mode, because some applications stops the execution of CMD.
Start /B ".\Dir\Your app.exe"
:: Then stay in background for a certain time
Timeout /T "Seconds"
:: Continue your code...
Pause&Exit
The start+timeout+taskkill waits exactly the given time. Since I needed to stop waiting if the process exits earlier, I created my own solution in C++.
The tuxliketimeout program mimics the GNU timeout. Feel free to download&compile from
https://github.com/cernoch/tuxliketimeout
In windows 10 the easiest way is with scriptrunner:
Demonstrate the timeout by running a pause command (this will kill the called process):
ScriptRunner.exe -appvscript cmd "/c" "pause" -appvscriptrunnerparameters -wait -timeout=20