redirecting stdout and stderr for a windows service

Discussion in 'Python' started by Ian Hobson, Sep 6, 2010.

  1. Ian Hobson

    Ian Hobson Guest

    Hi all,

    I am trying to redirect stdout and stderr on a python windows service,
    so that the service will not stall after 256 chars is written, and so I
    can use print for simple debugging.

    I have the following 4 lines (copy/pasted) in the source of my code.

    if __name__ == '__main__':
    sys.stdout = sys.stderr = open("d:\logfile.txt", "a")
    print "Starting up"
    win32serviceutil.HandleCommandLine(PythonService)

    When I run them as a free standing program, logfile.txt is created
    the text placed in it, and it crashed on the last line - no permissions
    to create a service. (Micro-cluless has no sudo command in Win7. :( )

    When I start the code as a service, it does not create the log file
    does not put anything in it, but the last line is executed and the
    service starts! There are no Events on the event log.

    When I stop the service, it stops. Still no log file. Still no events.

    I tried running the service with my account and not the system user.
    This gave me "run as service" permissions, but did not alter the results.

    What is happening?

    And how can I set up logging so that the service can simply restart,
    leaving the trackback in the log file for me to come to later.

    All help gratefully received. I've lost most of my remaining hair today
    on this one.

    Ian
    Ian Hobson, Sep 6, 2010
    #1
    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. Jon Landenburer

    redirecting stderr and stdout

    Jon Landenburer, May 12, 2004, in forum: Perl
    Replies:
    1
    Views:
    11,192
    Joe Smith
    May 13, 2004
  2. Jan Knop
    Replies:
    4
    Views:
    1,004
    Jan knob
    Nov 24, 2003
  3. Michael McGarry
    Replies:
    1
    Views:
    593
    Michael Fuhr
    Dec 16, 2004
  4. Ian
    Replies:
    0
    Views:
    385
  5. it_says_BALLS_on_your forehead
    Replies:
    2
    Views:
    237
    Joe Smith
    Jan 10, 2006
Loading...

Share This Page