topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 12:32 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Run At Specified Time  (Read 12279 times)

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
DONE: Run At Specified Time
« on: November 02, 2012, 05:15 AM »
We all know the sleep utility.  It takes as parameter the number of seconds to sleep before it exits.
I am looking for a command line utility which will SLEEP TILL A SPECIFIED TIME

example:-

sleeptill.exe 03:30

This program sleeps until the computer time is 03:30AM, and then exits.
It can be enhanced with date parameters also.
example :- sleeptill.exe 2012-11-02:03:30

This program can be used as a alternative to the windows task scheduler.  And can be used in batch files and so on...

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,610
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #1 on: November 02, 2012, 05:20 AM »
Could Skrommel's OpeningHours be close to what you need?

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #2 on: November 02, 2012, 06:25 AM »
Thanks a lot for the immediate response.
I will look at that program and see if it meets my need.

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #3 on: November 02, 2012, 08:00 AM »
What I had in mind was similar to sleep.exe, which will block the execution till the time is complete.
The "opening hours" program is like a scheduler.  It cannot be used inside a batch file :(

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,610
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #4 on: November 02, 2012, 09:13 AM »
I've checked with Google, but either it's not to be found, or I used the wrong search criteria, but I haven't found anything usable. :o

So I mocked up this small Delphi commandline tool: SleepTill.exe
- Version: 0.9.0
Usage:
SleepTill [date] [time] [/?]
[date] : Optional date in yyyy-mm-dd format, default: today
[time] : Optional time in hh:mm[:ss] format, if not supplied: 00:00
/? or -? : Show this helpmessage
Remarks:
- Either date or time, or both, should be provided to start the wait
- Date/time should be in the future to start the wait
- Pressing Ctrl-C stops the wait

Download attached zipped-up exe file removed because of update, below.
« Last Edit: November 14, 2012, 04:11 PM by Ath, Reason: New version, see below »

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,199
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #5 on: November 02, 2012, 05:32 PM »
If you can use an old DOS program, take a look at my earlier post: Re: NANY 2011 Pledge: Reliable File Watcher Batcher Robot

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #6 on: November 05, 2012, 04:52 AM »
hi Ath,
Thanks a lot. That is exactly what I was looking for.
Anyways, I scraped vbscript code from the internet and wrote one myself .
Am posting the code here .. may be it will help someone else


'================================================================================
'start of script
'
'Usage: wait.vbs 16:30
'Sleep till 4.30PM and then exits

Option Explicit

Dim WshShell
Dim strEventInfo
Dim intSeconds, intMicrotime

Set WshShell = CreateObject("WScript.Shell")

'================================================================================

dim inHour
dim inMinute
dim segments
segments = Split(WScript.Arguments.Item(0),":")
inHour = segments(0)
inMinute = segments(1)
inHour   = CInt(inHour)
inMinute = CInt(inMinute)
'Wscript.Echo "Hour   = " & inHour
'Wscript.Echo "Minute = " & inMinute

'================================================================================
while( (currHour <= inHour) and (currMinute < inMinute))

    dim now1
    now1=now()
    'Wscript.echo now1
    segments = Split(now1," ")
    dim timeComponent
    timeComponent = segments(1)
    'Wscript.echo "timeComponent = "+timeComponent
    dim currHour, currMinute, currSeconds
    segments = Split(timeComponent,":")
    currHour    = segments(0)
    currMinute  = segments(1)
    currSeconds = segments(2)
    'Wscript.echo "currHour    = "+currHour
    'Wscript.echo "currMinute  = "+currMinute
    'Wscript.echo "currSeconds = "+currSeconds
    currHour    = CInt(currHour)
    currMinute  = CInt(currMinute)
    currSeconds = CInt(currSeconds)

    'Wscript.echo currHour & ":" & currMinute
    WScript.Sleep 1000
wend
'================================================================================
'end of script

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #7 on: November 14, 2012, 03:10 AM »
Ath,
Is there a way to specify that I need to wait till the next day?  I do not want to update the script everytime to give the next day's date in the command.

for example:-
instead of
SleepTill.exe 2012-11-15
or
SleepTill.exe 2012-11-16

I should be able to give
SleepTill.exe NEXTDAY
or something similar.

regards

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,610
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #8 on: November 14, 2012, 05:51 AM »
I can add a feature like that. I'm not sure when I'll be working on the dev-system where I've made this tool. Maybe today, maybe tomorrow. Please hang-on.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,610
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #9 on: November 14, 2012, 04:09 PM »
SleepTill updated/reached version 1.0.0

By request I added a few parameters/features:
- Date and Time offsets from 'now' can be specified
- No longer accepts '-' as option-specifier (needed for the days offset)

The offset for days can be specified by using -+<days> instead of a date. (Both the - and the + need to be there!)
Specify the offset for hours or minutes (seconds is no useful option imho) by using :+<hours> or ::+<minutes>
If an hour or minute offset is given, it is calculated from the current time, not from 00:00, that wouldn't be usable.

The updated /? help message:

SleepTill 1.0.0 (c) 2012, Ath : Wait for a date/time to occur, then continue.
Usage:
SleepTill [date] [-+days] [time] [:+hours|::+mins] [/d] [/?]
[date] : Optional date in yyyy-mm-dd format, default: today
[-+days] : Add 'days' to current date to wait for
[time] : Optional time in hh:mm[:ss] format, if not supplied: 00:00
[:+hours|::+mins] : Add 'hours' or 'minutes' to current time
/d : Show some debugging info
/? : Show this helpmessage
Remarks:
- Either date or time, or both, should be provided to start the wait
- Date/time should be in the future to start the wait
- Pressing Ctrl-C stops the wait


Download attached zipfile and extract. Use as documented.

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #10 on: November 21, 2012, 01:53 AM »
I have written a C program which will do only what I had described as a requirement, ie.. wait till next day...
The source code is below...
/********************************************************************************/
/*
This program compiles fine on Microsoft Visual C++ 6.0.
Generated exe is 96kb in size.  How to reduce the size?
*/
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

int main(int argc, char* argv[])
{
    if(argc > 1) {
        printf("This program sleeps till the end of current day. ie.. exits when a new day starts.\n");
        return 0;
    }
    bool nextDay = false;
    char* inputDate = "";
    char* inputTime = "";
    struct tm *newtime;
    time_t long_time;

    time( &long_time );                /* Get time as long integer. */
    newtime = localtime( &long_time ); /* Convert to local time. */
    int currentDate = newtime->tm_mday;


    for( ;; ) { /* loop as along as required */
        _sleep(1000);
        time( &long_time );                /* Get time as long integer. */
        newtime = localtime( &long_time ); /* Convert to local time. */
        //printf( "%.19s %s\n", asctime( newtime ), am_pm );
        int newDate = newtime->tm_mday;
        if(currentDate != newDate ) { /* exit out of loop when date changes . ie.. next day */
            break;
        }
    }
    return 0;
}

/********************************************************************************/


Hope this helps someone.
Will attach binary tomorrow.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,610
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #11 on: November 21, 2012, 03:26 AM »
I have written a C program which will do only what I had described as a requirement, ie.. wait till next day...
That is what my 1.0.0 version, released a week ago (parameter: -+1), can do already... :-\

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #12 on: November 21, 2012, 04:35 AM »
Yes Ath, and thank you for that.
I was trying to replicate the functions of your utility... but it was too much work :(
so, I settled with a "one function only" utility :)

sprint907

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Run At Specified Time
« Reply #13 on: November 26, 2012, 12:08 AM »
Attaching the binary and source code in a zip file.

Thanks Ath and rjbull for their help.