How can I make a program automatically run once per day?

John Salerno johnjsal at gmail.com
Wed Jul 27 12:03:59 EDT 2011


On Jul 27, 7:58 am, Billy Mays
<81282ed9a88799d21e77957df2d84bd6514d9... at myhashismyemail.com> wrote:
> On 07/27/2011 08:35 AM, Chris Angelico wrote:
>
>
>
>
>
>
>
>
>
> > On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel<da... at ieee.org>  wrote:
> >> As Chris pointed out, you probably aren't getting the script's directory
> >> right.  After all, how can the scheduler guess where you put it?  The
> >> obvious answer is to use a full path for the script's filename.  Another
> >> alternative is to fill in the current directory in the appropriate field of
> >> the scheduler's entry.
>
> > I would prefer setting the current directory, as that allows the
> > script to find any data files it needs, but either works.
>
> >> I find it useful to only add batch files to the scheduler.  Those batch
> >> files can do any setup and cleanup necessary.  In this case, the batch file
> >> might simply set the current directory to the location of the script.
>
> > And that is an excellent idea. Definitely recommended.
>
> > ChrisA
>
> If it hasn't been mentioned already:
>
> import time
>
> while True:
>      t1 = time.time()
>
>      #your code here
>
>      t2 = time.time()
>      time.sleep( 86400 - (t2 - t1) )
>
> This doesn't take into account leap seconds, but it doesn't depend on a
> task scheduler.  It is also independent of the time your code takes to
> execute.
>
> This is simpler, but it might drift slightly over time.
>
> --
> Bill

Well, I specified the full path name but it still doesn't seem to
work. A DOS prompt flashes for about a second that says "taskeng.exe"
in the title bar, but the script itself still isn't being run.

I don't know about batch files but I'll read up on them and see if
that will be a better solution.



More information about the Python-list mailing list