Windows XP - cron or scheduler for Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric @ Zomething

    Windows XP - cron or scheduler for Python?


    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 isthere 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

    ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::
    e-mail me at:
    do@something.co m
    except, increment the "d" and "o" by one letter
    and spell something with a "z"
    ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::

  • Peter Hansen

    #2
    Re: Windows XP - cron or scheduler for Python?

    Eric @ Zomething wrote:
    [color=blue]
    > 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?[/color]

    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

    Comment

    • Larry Bates

      #3
      Re: Windows XP - cron or scheduler for Python?

      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" <eric@zomething .com> wrote in message
      news:mailman.78 .1087794803.454 .python-list@python.org ...

      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

      ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::
      e-mail me at:
      do@something.co m
      except, increment the "d" and "o" by one letter
      and spell something with a "z"
      ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::


      Comment

      • Peter Hansen

        #4
        Re: Windows XP - cron or scheduler for Python?

        Larry Bates wrote:
        [color=blue]
        > 2) Always call Python and have it run the application.
        > Don't just try to run progname.py.[/color]

        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

        Comment

        • Ivan Voras

          #5
          Re: Windows XP - cron or scheduler for Python?

          Peter Hansen wrote:[color=blue]
          > Larry Bates wrote:
          >[color=green]
          >> 2) Always call Python and have it run the application.
          >> Don't just try to run progname.py.[/color]
          >
          >
          > 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).[/color]

          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)

          Comment

          • Peter Hansen

            #6
            Re: Windows XP - cron or scheduler for Python?

            Ivan Voras wrote:
            [color=blue]
            > Peter Hansen wrote:
            >[color=green]
            >> Larry Bates wrote:
            >>[color=darkred]
            >>> 2) Always call Python and have it run the application.
            >>> Don't just try to run progname.py.[/color]
            >>
            >> 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).[/color]
            >
            > 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)[/color]

            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

            Comment

            • Thorsten Kampe

              #7
              Re: Windows XP - cron or scheduler for Python?

              * Peter Hansen (2004-06-21 19:35 +0200)[color=blue]
              > Ivan Voras wrote:[color=green]
              >> Peter Hansen wrote:[color=darkred]
              >>> 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).[/color]
              >>
              >> 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)[/color]
              >
              > 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...[/color]

              "PATHEXT" enables you to run files in the path with these extensions
              without extension (for example "winword" instead of "winword.ex e").
              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

              Comment

              • Jay Donnell

                #8
                Re: Windows XP - cron or scheduler for Python?

                > 2) Always call Python and have it run the application.[color=blue]
                > Don't just try to run progname.py.[/color]

                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.

                Comment

                • Peter Hansen

                  #9
                  Re: Windows XP - cron or scheduler for Python?

                  Jay Donnell wrote:
                  [color=blue][color=green]
                  >>2) Always call Python and have it run the application.
                  >>Don't just try to run progname.py.[/color]
                  >
                  > 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.[/color]

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

                  c:\a\python23\p ython.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.Message Box('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

                  Comment

                  • Roger Upole

                    #10
                    Re: Windows XP - cron or scheduler for Python?

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

                    import pythoncom, win32api
                    from win32com.tasksc heduler import taskscheduler
                    ts=pythoncom.Co CreateInstance( taskscheduler.C LSID_CTaskSched uler,None,

                    pythoncom.CLSCT X_INPROC_SERVER ,taskscheduler. IID_ITaskSchedu ler)
                    task=ts.Activat e('your task name')
                    exit_code,start up_error_code=t ask.GetExitCode ()
                    print win32api.Format Message(startup _error_code)
                    hth
                    Roger


                    "Jay Donnell" <jaydonnell@yah oo.com> wrote in message
                    news:a6fdfd6b.0 406211455.6bd70 abf@posting.goo gle.com...[color=blue][color=green]
                    > > 2) Always call Python and have it run the application.
                    > > Don't just try to run progname.py.[/color]
                    >
                    > 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.[/color]


                    Comment

                    • Roger Upole

                      #11
                      Re: Windows XP - cron or scheduler for Python?

                      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" <peter@engcorp. com> wrote in message
                      news:aN2dndDVVe QO4kvdRVn-sw@powergate.ca ...[color=blue]
                      > Eric @ Zomething wrote:
                      >[color=green]
                      > > I'm trying to have some scripts run periodically on Windows XP and found[/color][/color]
                      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.[color=blue][color=green]
                      > >
                      > > Has anyone used the Windows Task Scheduler to run .py scripts, and if so[/color][/color]
                      is there some intracacy to it?[color=blue]
                      >
                      > 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[/color]


                      Comment

                      • Valery Kondakoff

                        #12
                        Re: Windows XP - cron or scheduler for Python?

                        "Eric @ Zomething" <eric@zomething .com> wrote in message news:<mailman.7 8.1087794803.45 4.python-list@python.org >...
                        [color=blue]
                        > Is there a more UNIX version of a cron program one can run on Windows?[/color]

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

                        scheduler,cron,crontab,automation,winspy,service,backup,dump,incremental,synchronization,nnCron,nnBackup,free,freeware,nnsync

                        Comment

                        • Peter Hansen

                          #13
                          Re: Windows XP - cron or scheduler for Python?

                          Roger Upole wrote:
                          [color=blue]
                          > 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)[/color]

                          Wow, now there's someone who's been delving deep into the innards
                          of MSDN. How do you guys *know* this stuff?! :-)

                          Comment

                          • googlePoster

                            #14
                            Re: Windows XP - cron or scheduler for Python?

                            "Larry Bates" <lbates@swamiso ft.com> wrote in message news:<b92dnUC9u-vPf0vd4p2dnA@co mcast.com>...[color=blue]
                            > 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" <eric@zomething .com> wrote in message
                            > news:mailman.78 .1087794803.454 .python-list@python.org ...
                            >
                            > 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:
                            > do@something.co m
                            > except, increment the "d" and "o" by one letter
                            > and spell something with a "z"
                            > ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::::::::: ::::::::[/color]


                            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

                            Comment

                            • Emilio

                              #15
                              Re: Windows XP - cron or scheduler for Python?

                              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:
                              Download Python Cron - Great Cron for Windows! for free. This is a clone of the well-known cron job scheduler for the unix flavored operating systems. The implementation is platform-independant, robust and simple.


                              Emilio.

                              Comment

                              Working...