DOS TIME command

I'm currently attempting to write a batch file in DOS that will open a program when the interal clock hits a certain time.

This is what I have so far:

@ECHO OFF
 :Run
VER | TIME > TEMP.BAT
ECHO SET TIME=%%3>CURRENT.BAT
CALL TEMP.BAT
DEL TEMP.BAT
DEL CURRENT.BAT
ECHO It's now %TIME%
IF %TIME%=="10:33:00.00a" START c:/myprog.exe GOTO END
GOTO Run

 :End

If you're familiar with the TIME command, you know what my problem is. The loop is working perfectly and comparing the time to the string I specify, but the time it takes to execute the loop is not a perfect second. The clock never reaches 10:30:00.00a, but it does hit 10:30:00.01a, 10:30:01.03a, etc. Presumably, if I ran this batch file at precisely the right time, the interal clock would hit 00.00 and the program would spawn, but that's impossible to count on.

I'm new to batch file programming, and I know what I need to do is extract the hour and minute parts of the time command and compare them, but I'm at a loss as how to do this. Previously, I attempted to use wildcard characters in my compare string for the second arguments, but that did not work either.

Can anyone help?
punkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uecasmCommented:
All else aside, there are a couple of bugs on your comparison line:

IF %TIME%=="10:33:00.00a" START c:/myprog.exe GOTO END

Firstly, you have to start "c:\myprog.exe" - you used the wrong kind of slash.

Secondly, since %TIME% doesn't contain quotes itself, you have to either remove the quotes around the comparison time, or write "%TIME%"=="10:33:00.00a"

However, neither of these will actually solve your problem (unless you're lucky).  The main problem is that you're seeing the hundredths of a second; and you can't mask these off in straight DOS.

There are a number of ways to solve this, the easiest probably to write a program that returns the current time without the hundredths.  In this case you would have to be careful that the program is only called once; in your code above it's possible for it to be called more than once in succession.

If you have Windows 95 (with Plus), Windows 98 or later, you should use the System Agent/Task Scheduler instead - it's more reliable.
0
punkerAuthor Commented:
Thank you for pointing out the many bugs in my code. As I'm new to DOS batch files, that's to be expected.

Yes, I know my problem lies in the seconds and hundredths of a second being returned by the time command. My hope is that someone will know of a way to extract the hour and minute from the time command so I may compare them.

If anyone knows how to do this via DOS batch file programming, please respond.
0
uecasmCommented:
As I said, you cannot do it purely in DOS; you need help from a real programming language such as C or BASIC.

To help you out, I wrote a little program that will let you get the time without the hundredths, or without the seconds, or whatever.
Get it at http://ue.cjb.net/curtime.zip

There's a text file in there which explains how to use the program.

And don't forget to modify your code to avoid multiple executions, especially if you ignore the seconds.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

punkerAuthor Commented:
There MUST be a way to do this in DOS. I can't accept being told an operating system simply can't do something, especially when I'm quite sure it can be done.
I need to do this all in DOS. C or BASIC are out of the question.
The multiple executions are there so the batch file can be run at any time and will continue executing until the specified time, and will then open the program in question. So I can't see how to avoid that.
I haven't downloaded your zip file, partially because I'm not sure what's in it, but mostly because I'm very wary of downloading anything from the internet. If what is in the zip file is an all DOS solution, could you possibly post the code instead of hyperlinking to a download site?

I'm rejecting because I'd like to keep this open to all until I find an answer I can live with. Since I can accept comments as answers, there isn't any reason to lock the question.
0
KangaRooCommented:
Take a look at FIND. You could use something like
VER |  TIME | FIND "15:02"
if errorlevel

FIND will set errorlevel depending on result. I've forgotten the exact values but you can easily test.
0
KangaRooCommented:
Another option is to write a small programm to check the current time. It could do several things:
- set the errorlevel if current time is within certain criteria.
- wait until the specified time.
0
KangaRooCommented:
And of course, execute a specified program at a pre-determined time (a kind of scheduler)
0
KangaRooCommented:
@echo off
:loop
   VER | TIME | FIND "15:02"
   if errorlevel 2 goto error
   if errorlevel 1 goto loop
:itistime
   echo Its time!
   goto endit
:error
  echo An error occurred!
:endit
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
punkerAuthor Commented:
Brilliant! I knew it was something really simple I wasn't catching.

Thanks a lot!

0
KangaRooCommented:
Yeah, writing batches often involves serious abuse of all kinds of tools and commands ;) Can be real fun though :-))
You're welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.