Windows XP - cron or scheduler for Python?

Discussion in 'Python' started by Eric @ Zomething, Jun 20, 2004.

  1. I'm trying to have some scripts run periodically on Windows XP and found the "Task Scheduler" did not execute my scripts. My scripts are of the form scriptName.py, and will run just by invoking that name in the Command Prompt.

    Has anyone used the Windows Task Scheduler to run .py scripts, and if so is there some intracacy to it?

    Is there a more UNIX version of a cron program one can run on Windows?

    Has anyone written a simple cron program for Windows in Python, or does anyone see any complication with doing that (which I have not grasped)?

    Do I just need to build myself an **IX box?





    Eric Pederson
    http://www.songzilla.blogspot.com
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    e-mail me at:

    except, increment the "d" and "o" by one letter
    and spell something with a "z"
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
     
    Eric @ Zomething, Jun 20, 2004
    #1
    1. Advertising

  2. Eric @ Zomething

    Peter Hansen Guest

    Eric @ Zomething wrote:

    > I'm trying to have some scripts run periodically on Windows XP and found the "Task Scheduler" did not execute my scripts. My scripts are of the form scriptName.py, and will run just by invoking that name in the Command Prompt.
    >
    > Has anyone used the Windows Task Scheduler to run .py scripts, and if so is there some intracacy to it?


    I had not tried it, so I just did. My first attempt failed. As it
    turned out, it was because I ignore the password field, assuming
    it would be able to run anyway while I was logged in. The "status"
    field in the Task Scheduler window showed the reason... once I
    fixed that, it did work, either as "c:/tick.py" (make sure you
    include the right path here or in the "start in this folder" field)
    or as "c:/a/python23/python.exe c:/tick.py".

    If it's not working, double-check the status field to see why it
    didn't work...

    -Peter
     
    Peter Hansen, Jun 21, 2004
    #2
    1. Advertising

  3. Eric @ Zomething

    Larry Bates Guest

    I run python programs ALL the time on Windows XP
    using the scheduler. Two things you must
    remember when doing this:

    1) Your program runs in a "different" environment
    than your foreground application. It DOES NOT
    inherit drive mappings, environment variables,
    paths, etc. so you must fully qualify everything.

    2) Always call Python and have it run the application.
    Don't just try to run progname.py.

    HTH,

    Larry Bates
    Syscon, Inc.

    "Eric @ Zomething" <> wrote in message
    news:...

    I'm trying to have some scripts run periodically on Windows XP and found the
    "Task Scheduler" did not execute my scripts. My scripts are of the form
    scriptName.py, and will run just by invoking that name in the Command
    Prompt.

    Has anyone used the Windows Task Scheduler to run .py scripts, and if so is
    there some intracacy to it?

    Is there a more UNIX version of a cron program one can run on Windows?

    Has anyone written a simple cron program for Windows in Python, or does
    anyone see any complication with doing that (which I have not grasped)?

    Do I just need to build myself an **IX box?





    Eric Pederson
    http://www.songzilla.blogspot.com
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    e-mail me at:

    except, increment the "d" and "o" by one letter
    and spell something with a "z"
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
     
    Larry Bates, Jun 21, 2004
    #3
  4. Eric @ Zomething

    Peter Hansen Guest

    Larry Bates wrote:

    > 2) Always call Python and have it run the application.
    > Don't just try to run progname.py.


    This actually works, though, at least on my system. It
    might be because I inserted .py in the PATHEXT env var
    globally, though I thought it was just because running
    a .py is possible simply by clicking on it in Explorer
    (ie. the File Association does the job).

    -Peter
     
    Peter Hansen, Jun 21, 2004
    #4
  5. Eric @ Zomething

    Ivan Voras Guest

    Peter Hansen wrote:
    > Larry Bates wrote:
    >
    >> 2) Always call Python and have it run the application.
    >> Don't just try to run progname.py.

    >
    >
    > This actually works, though, at least on my system. It
    > might be because I inserted .py in the PATHEXT env var
    > globally, though I thought it was just because running
    > a .py is possible simply by clicking on it in Explorer
    > (ie. the File Association does the job).


    No, putting .py in PATHEXT is necessary. That way, you can run python
    programs from the command line (cmd) using just "scriptname", without the
    extension! (it performs just like .bat, .exe and similar files)
     
    Ivan Voras, Jun 21, 2004
    #5
  6. Eric @ Zomething

    Peter Hansen Guest

    Ivan Voras wrote:

    > Peter Hansen wrote:
    >
    >> Larry Bates wrote:
    >>
    >>> 2) Always call Python and have it run the application.
    >>> Don't just try to run progname.py.

    >>
    >> This actually works, though, at least on my system. It
    >> might be because I inserted .py in the PATHEXT env var
    >> globally, though I thought it was just because running
    >> a .py is possible simply by clicking on it in Explorer
    >> (ie. the File Association does the job).

    >
    > No, putting .py in PATHEXT is necessary. That way, you can run python
    > programs from the command line (cmd) using just "scriptname", without
    > the extension! (it performs just like .bat, .exe and similar files)


    Are you sure? I just tried removing .py from my PATHEXT and
    not only did it still work from Explorer, it even worked from
    the command line!

    Then I tried redirecting the File Assocation under File Types
    to point to notepad instead of python. Now typing "xxx.py"
    at the command line or clicking on the xxx.py file in
    Explorer both launch Notepad to edit the file.

    I'm not sure what PATHEXT is really needed for, but executing
    ..py files on the command line in Windows XP does not seem to
    be one of them...

    -Peter
     
    Peter Hansen, Jun 21, 2004
    #6
  7. * Peter Hansen (2004-06-21 19:35 +0200)
    > Ivan Voras wrote:
    >> Peter Hansen wrote:
    >>> Larry Bates wrote:
    >>>> 2) Always call Python and have it run the application.
    >>>> Don't just try to run progname.py.
    >>>
    >>> This actually works, though, at least on my system. It
    >>> might be because I inserted .py in the PATHEXT env var
    >>> globally, though I thought it was just because running
    >>> a .py is possible simply by clicking on it in Explorer
    >>> (ie. the File Association does the job).

    >>
    >> No, putting .py in PATHEXT is necessary. That way, you can run python
    >> programs from the command line (cmd) using just "scriptname", without
    >> the extension! (it performs just like .bat, .exe and similar files)

    >
    > Are you sure? I just tried removing .py from my PATHEXT and
    > not only did it still work from Explorer, it even worked from
    > the command line!
    >
    > Then I tried redirecting the File Assocation under File Types
    > to point to notepad instead of python. Now typing "xxx.py"
    > at the command line or clicking on the xxx.py file in
    > Explorer both launch Notepad to edit the file.
    >
    > I'm not sure what PATHEXT is really needed for, but executing
    > .py files on the command line in Windows XP does not seem to
    > be one of them...


    "PATHEXT" enables you to run files in the path with these extensions
    without extension (for example "winword" instead of "winword.exe").
    The cmd shell actually performs an "open" action. For executables
    "opening" is running them. For documents it's starting the associated
    application and opening the document in it. For .py both things are
    reasonable.

    Thorsten
     
    Thorsten Kampe, Jun 21, 2004
    #7
  8. Eric @ Zomething

    Jay Donnell Guest

    > 2) Always call Python and have it run the application.
    > Don't just try to run progname.py.


    How would one do this. I'm a unix geek having the same problems as the
    op, but I'm on windows 2000. The status simply says "couldn't start".
    Any other ideas would be appreciated as well.
     
    Jay Donnell, Jun 21, 2004
    #8
  9. Eric @ Zomething

    Peter Hansen Guest

    Jay Donnell wrote:

    >>2) Always call Python and have it run the application.
    >>Don't just try to run progname.py.

    >
    > How would one do this. I'm a unix geek having the same problems as the
    > op, but I'm on windows 2000. The status simply says "couldn't start".
    > Any other ideas would be appreciated as well.


    For starters, try full absolute paths for both parts. On
    my machine, for example, this is pretty much guaranteed
    to run:

    c:\a\python23\python.exe c:\tick.py

    This was just the following script, which you might want
    to try as a test, but it works only if the pywin32 stuff
    (formerly known as win32all) is installed:

    import win32ui
    win32ui.MessageBox('it works!', 'Tick', 0)

    If even that doesn't work (after correcting the paths
    and module name for your own system), open a command prompt
    (Start->Run then type "cmd" and hit enter) and type
    exactly the same thing there. If *that* doesn't work,
    you don't even have Python installed properly...

    -Peter
     
    Peter Hansen, Jun 22, 2004
    #9
  10. Eric @ Zomething

    Roger Upole Guest

    You can retrieve the startup error code using the Pywin32 package.
    (requires build 201)

    import pythoncom, win32api
    from win32com.taskscheduler import taskscheduler
    ts=pythoncom.CoCreateInstance(taskscheduler.CLSID_CTaskScheduler,None,

    pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler)
    task=ts.Activate('your task name')
    exit_code,startup_error_code=task.GetExitCode()
    print win32api.FormatMessage(startup_error_code)
    hth
    Roger


    "Jay Donnell" <> wrote in message
    news:...
    > > 2) Always call Python and have it run the application.
    > > Don't just try to run progname.py.

    >
    > How would one do this. I'm a unix geek having the same problems as the
    > op, but I'm on windows 2000. The status simply says "couldn't start".
    > Any other ideas would be appreciated as well.
     
    Roger Upole, Jun 22, 2004
    #10
  11. Eric @ Zomething

    Roger Upole Guest

    You can actually run tasks under your userid without a password
    if you're logged in. However, you have to set a certain flag for the task.
    (TASK_FLAG_RUN_ONLY_IF_LOGGED_ON)
    You can do this programatically using Pywin32.
    Roger

    "Peter Hansen" <> wrote in message
    news:...
    > Eric @ Zomething wrote:
    >
    > > I'm trying to have some scripts run periodically on Windows XP and found

    the "Task Scheduler" did not execute my scripts. My scripts are of the form
    scriptName.py, and will run just by invoking that name in the Command
    Prompt.
    > >
    > > Has anyone used the Windows Task Scheduler to run .py scripts, and if so

    is there some intracacy to it?
    >
    > I had not tried it, so I just did. My first attempt failed. As it
    > turned out, it was because I ignore the password field, assuming
    > it would be able to run anyway while I was logged in. The "status"
    > field in the Task Scheduler window showed the reason... once I
    > fixed that, it did work, either as "c:/tick.py" (make sure you
    > include the right path here or in the "start in this folder" field)
    > or as "c:/a/python23/python.exe c:/tick.py".
    >
    > If it's not working, double-check the status field to see why it
    > didn't work...
    >
    > -Peter
     
    Roger Upole, Jun 22, 2004
    #11
  12. "Eric @ Zomething" <> wrote in message news:<>...

    > Is there a more UNIX version of a cron program one can run on Windows?


    Take a look at nnCron LITE (freeware): small but powerful cron/anacron Windows port.

    http://www.nncron.ru
     
    Valery Kondakoff, Jun 22, 2004
    #12
  13. Eric @ Zomething

    Peter Hansen Guest

    Roger Upole wrote:

    > You can actually run tasks under your userid without a password
    > if you're logged in. However, you have to set a certain flag for the task.
    > (TASK_FLAG_RUN_ONLY_IF_LOGGED_ON)


    Wow, now there's someone who's been delving deep into the innards
    of MSDN. How do you guys *know* this stuff?! :)
     
    Peter Hansen, Jun 22, 2004
    #13
  14. Eric @ Zomething

    googlePoster Guest

    "Larry Bates" <> wrote in message news:<>...
    > I run python programs ALL the time on Windows XP
    > using the scheduler. Two things you must
    > remember when doing this:
    >
    > 1) Your program runs in a "different" environment
    > than your foreground application. It DOES NOT
    > inherit drive mappings, environment variables,
    > paths, etc. so you must fully qualify everything.
    >
    > 2) Always call Python and have it run the application.
    > Don't just try to run progname.py.
    >
    > HTH,
    >
    > Larry Bates
    > Syscon, Inc.
    >
    > "Eric @ Zomething" <> wrote in message
    > news:...
    >
    > I'm trying to have some scripts run periodically on Windows XP and found the
    > "Task Scheduler" did not execute my scripts. My scripts are of the form
    > scriptName.py, and will run just by invoking that name in the Command
    > Prompt.
    >
    > Has anyone used the Windows Task Scheduler to run .py scripts, and if so is
    > there some intracacy to it?
    >
    > Is there a more UNIX version of a cron program one can run on Windows?
    >
    > Has anyone written a simple cron program for Windows in Python, or does
    > anyone see any complication with doing that (which I have not grasped)?
    >
    > Do I just need to build myself an **IX box?
    >
    >
    >
    >
    >
    > Eric Pederson
    > http://www.songzilla.blogspot.com
    > ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    > e-mail me at:
    >
    > except, increment the "d" and "o" by one letter
    > and spell something with a "z"
    > ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



    i just found a cool scheduler called pycron that apparently is written
    in python

    *my* problem is i forgot how to make python scripts executable -- i have
    this foggy memory of 'if __name__ == "__main__":' not getting triggered
    if you're using something other than the command prompt, but i am failing
    to find it written down anywhere, and pycron tells me it ran my scripts,
    but nothing actually happens -- very frustrating
     
    googlePoster, Jul 2, 2004
    #14
  15. Eric @ Zomething

    Emilio Guest

    I have gone through the pain of trying to use those commands and use
    other available cron clients for Windows to find they are expensive, or
    have bugs and are not stable. So I wrote a very simple yet powerful
    script that handles all the basic functionality of Cron. It has been
    stable and used in production for about a year. The source code is in
    Python and you can read it, it is a simple page. I have also created a
    version for Windows with an installer that doesn't even require Python
    installed in the target machine.

    You can find the project here:
    http://sourceforge.net/projects/pycron

    Emilio.
     
    Emilio, Dec 23, 2004
    #15
  16. Eric @ Zomething

    Guest

    Hi,
    I thought I'd throw in my 2 cents worth.

    I have written a freeware task scheduler that might be of interest to
    you.
    It's called Kirby Alarm And Task Scheduler.
    Over 16000 people around the world use it.

    Kirby Alarm will run a program, pop up a note, play a sound, or send an
    email at whatever intervals you like.
    Have a look at http://www.kirbyfooty.com/
    or read what others have to say about it at
    http://www.download.com/Kirby-Alarm-And-Task-Scheduler/3000-2084_4-10260143.html?tag=stbc.gp

    To run a python script just put the following into the program name.
    (The quotes MUST be included wherever there are spaces in the command
    line)

    "C:\Python23\python.exe" "d:\mypython\Say Time.py"
    Have a great Christmas!

    God bless

    Ian
     
    , Dec 24, 2004
    #16
  17. Emilio wrote:
    > I have gone through the pain of trying to use those commands and use
    > other available cron clients for Windows to find they are expensive, or
    > have bugs and are not stable. So I wrote a very simple yet powerful
    > script that handles all the basic functionality of Cron. It has been
    > stable and used in production for about a year. The source code is in
    > Python and you can read it, it is a simple page. I have also created a
    > version for Windows with an installer that doesn't even require Python
    > installed in the target machine.
    >
    > You can find the project here:
    > http://sourceforge.net/projects/pycron
    >
    > Emilio.
    >


    I find your project useful, but it's not a full "operation planned"
    replacement. (I hope I have translate correctly from Italian "Operazioni
    pianificate", you'll find it into the control panel).
    It's mean that lack the service function. For example, if the pc is
    lighted, but no logged-in, pycron don't work!

    Why don't add this function? I think that is simple to make with py2exe
    help.

    If you want I can create a simple GUI that can help the users that have
    no knowledge whit contrab sintax.

    Michele
     
    Michele Petrazzo, Dec 24, 2004
    #17
  18. wrote:
    > Hi,
    > I thought I'd throw in my 2 cents worth.
    >
    > I have written a freeware task scheduler that might be of interest to
    > you.
    > It's called Kirby Alarm And Task Scheduler.
    > Over 16000 people around the world use it.


    Hi,

    Was this written in Python? If so 2 quick questions:

    1. what did you use to write the GUI?

    2. any chance we could see some of the code for this? (I understand
    if not of course)

    Thanks,

    Esmail
    ps: I downloaded the program just a few minutes ago to check out.
     
    Esmail Bonakdarian, Dec 27, 2004
    #18
  19. Eric @ Zomething

    Guest

    Hi Esmail,
    Kirby Alarm is written in Clarion.
    Sorry, but I want to keep the source code to myself.
    Ian
     
    , Dec 27, 2004
    #19
  20. wrote:
    > Hi Esmail, Kirby Alarm is written in Clarion. Sorry, but I want to
    > keep the source code to myself.


    Hi, thanks for the info, and no problem.

    I'm learning Python, and looking at other's code has been a
    great way to learn. (As an aside, I was thinking of this
    sort of application as a good project).

    cheers,
    Esmail
     
    Esmail Bonakdarian, Dec 27, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    8
    Views:
    9,623
  2. Christina Robertson

    Windows 2000, scheduler and java

    Christina Robertson, Sep 10, 2003, in forum: Java
    Replies:
    2
    Views:
    1,792
  3. Tim Golden
    Replies:
    4
    Views:
    579
    Emilio
    Dec 23, 2004
  4. Allan Palmer

    Interacting with Windows Scheduler

    Allan Palmer, Jun 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    158
    ccallen
    Jun 7, 2004
  5. manika02

    WebServices and Windows Scheduler

    manika02, Mar 31, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    157
    manika02
    Mar 31, 2006
Loading...

Share This Page