Page 1 of 1

WaitUntil - batch command replacement for scheduler

Posted: Mon Jan 04, 2021 9:51 pm
by FWExplorer
I'd like to take some of the applications in the office out of the Windows Scheduler, and just put it in a batch file that waits until a specified time.

I already use Timeout for certain tasks. And there are variations of this, out on the web.

But I haven't found anything like a WaitUntil command. I'm pretty sure I could build it in Harbour/Fivewin, within a week. But since there doesn't seem to be an existing command out there, or maybe it's more difficult than it seems on the surface.

Can anyone think of a reason that an executable that runs like

WaitUntil <Day> <Time Range>

e.g.

WaitUntil Mon "13:50" "14:10"

would be difficult?

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 10:07 am
by Antonio Linares

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 11:07 am
by FWExplorer
Unfortunately, it doesn't address the specification of a specific time. These are just variations of timeout, where you specify the number of seconds.

I'd want a child program or batch to run, e.g. at 11:15 am, regardless of when the parent calling batch starts. So we don't know the number of seconds, in advance.

There has to be some reason why a utility that specifies the time to run something is so rare. There must be some inherent difficulty, or maybe people prefer to use the windows scheduler because it's already there.

I think I just have to hack around, do some coding, and become more familiar with the problem.

Thanks, Antonio.

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 11:26 am
by FWExplorer

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 8:28 pm
by Antonio Linares
D.

You can build it using FWH this way:

example of use (from cmd.exe)
tarry 21:26

tarry.prg

Code: Select all

#include "FiveWin.ch"

function Main( cTime )

   if cTime != nil 
      while Time() < cTime
         SysRefresh()
      end

      // DoWhatever()
   endif
   
return nil

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 9:23 pm
by FWExplorer
Thanks Antonio,

But unfortunately, it's not exactly what I'm trying to build.

Anyway, I'm very close. I'll share the code shortly.


Antonio Linares wrote:D.

You can build it using FWH this way:

example of use (from cmd.exe)
tarry 21:26

tarry.prg

Code: Select all

#include "FiveWin.ch"

function Main( cTime )

   if cTime != nil 
      while Time() < cTime
         SysRefresh()
      end

      // DoWhatever()
   endif
   
return nil

Re: WaitUntil - batch command replacement for scheduler

Posted: Tue Jan 05, 2021 11:33 pm
by FWExplorer
Hi Antonio,

This is what I was (unsuccessfully) trying to describe.

https://raw.githubusercontent.com/HBEnt ... tUntil.prg

The executable WaitUntil.exe is also on that hub.

I haven't fully tested it in more than 4 circumstances yet, but the syntax is

WaitUntil <Day> <Time>


So, in order to wait until Friday at 1:15 pm, you would type

WaitUntil "Friday" "13:15:00"


Regards,

Re: WaitUntil - batch command replacement for scheduler

Posted: Wed Jan 06, 2021 9:03 pm
by nageswaragunupudi
This works for me.

waituntil.prg

Code: Select all

#include "fivewin.ch"

function Main()

   local cDay  := HB_ARGV( 1 )
   local nSec  := TIMETOSEC( HB_ARGV( 2 ) )
   local n

   do while !( CDOW( Date() ) = cDay )
      Sleep( ( 86401 - Seconds() ) * 1000 )
   enddo

   do while ( n := Seconds() ) < nSec
      Sleep( ( nSec - n ) * 1000 )
   enddo

   ? "Start work"

return nil
 

Re: WaitUntil - batch command replacement for scheduler

Posted: Thu Jan 07, 2021 12:09 am
by FWExplorer
Looks good, I'll put it through its paces, thanks.

nageswaragunupudi wrote:This works for me.

waituntil.prg

Code: Select all

#include "fivewin.ch"

function Main()

   local cDay  := HB_ARGV( 1 )
   local nSec  := TIMETOSEC( HB_ARGV( 2 ) )
   local n

   do while !( CDOW( Date() ) = cDay )
      Sleep( ( 86401 - Seconds() ) * 1000 )
   enddo

   do while ( n := Seconds() ) < nSec
      Sleep( ( nSec - n ) * 1000 )
   enddo

   ? "Start work"

return nil