Subj : Re: Timed Event in windows file? (batch possibly?) To : comp.programming From : ratedr1 Date : Tue Jul 26 2005 12:54 pm Unfortunately I dont understand this at ALL :( so sorry, I did try!!. Let me give you an example and see if you could help me more if its not too much trouble. The machine now accepts programs written just like this...and this is ALL that it accepts 1,amps,50 1,timer,100 1,hon LETS CALL THAT FILE "C.TXT" that sets the amps to 50, for 100 seconds, then turns the machine on (where it starts the timer itself) what Id need to do (and if you can work with that example it would be great), is make it run this program FIRST 1,amps,0 1,timer,5 1,hon LETS CALL THIS "A.TXT" which would not run any power through it for 5 seconds...THEN run the above program ...so basically I would need the timer program that youd help me with to send A.TXT and then wait 5 seconds and send C.txt. Is this possible? does it make any sense? Thanks so much in advance Scott Rob Morris wrote: > ratedr1@aol.com wrote: > > Is it possible to add a timer/timed event in a batch or txt file? > [Snip!] > > Hi, I think there are better ways to script on Windows than using batch > files, but you can still do fairly powerful stuff with them, mainly with > the 'FOR' and 'IF' commands. There is a %TIME% environment variable, > which you could send to a file, and then parse it using the 'FOR /f' > command (it reads through files and can be told a separator token). > Maybe something like this: > > @echo off > : start > > rem Put time in h:m:s into a file > echo %time% >temp_time.txt > > rem Pull out number of seconds, loop until it's zero. > for /f "delims=:. tokens=3" %%i in (temp_time.txt) do ( > if %%i==00 ( > echo 0 seconds. Starting... > ) else ( > echo %%i > goto start > ) > ) > > Now, this is fairly naff and is linked to seconds in the minute, not > time elapsed. But it could be extended to a whole list of commands by > using another FOR loop with a list of commands and when to do them. > > e.g. a control.txt file with a list of what to do > > === control.txt === > 00:echo 00:echo Hello > 15:echo 15 > 30:echo 30 > =================== > > A helper, wait_until.bat > === wait_until.bat ========== > @echo off > > : start > > rem Put time in h:m:s into a file > echo %time% >temp_time.txt > > rem Pull out number of seconds, loop until it's zero. > for /f "delims=:. tokens=3" %%i in (temp_time.txt) do ( > if %%i neq %1 ( > goto start > ) > ) > =========================== > > > And the main file: > === timing.bat === > @echo off > > rem Read control.txt one set of commands at a time > rem > for /f "delims=: tokens=1,2,3" %%a in (control.txt) do ( > echo Current line says %%a %%b %%c > wait_until %%a > @echo off > rem Now do commands > %%b > %%c > ) > ================== > > > You see? timing.bat reads control.txt, waits until the number of > seconds it's told to, then executes up to two commands (the second and > third tokens on the line in control.txt). Then it reads the next line > of control.txt, and so on. (Note the separate wait_until.bat, I had > problems trying to do it all in one file). > > Anyway, this isn't a great way of doing things. I'm sure someone could > write something better in C in about five minutes. I ploughed on with > it once I'd started but I don't think it's very good. Good luck anyway. > Cheers, > Rob M > > -- > Rob Morris: arr emm four four five (at) cam dot ac dot uk .