[python-win32] How to invoke Python program from Windows service?

Mark Hammond mhammond at skippinet.com.au
Fri Jun 22 14:57:53 CEST 2012


Services are pretty tricky - you might be better off arranging for the 
Python script to write sys.stderr somewhere useful and seeing what the 
traceback says - you'll almost certainly strike the same problem after 
you get a pywin32 based one close to working.

Mark

On 22/06/2012 9:19 PM, Funke, Matt wrote:
>> Note you can write the service directly in Python using pywin32.  If
>> you want to write the service using some other technology and just
>> spawn Python, then I'd suggest using just CreateProcess.  But with
>> both CreateProcess and ProcessStartInfo, you need a way to
>> redirect output from the Python process so you can get diagnostics
>> from the output - just telling us it is "unsuccessful" doesn't help us
>> tell you what problem you have.
>
> Yeah, that was exactly my problem; I had no way to diagnose what was going on, and needed a springboard to tell me what I needed to know in order to figure out what was happening (or not).  I could verify that the script *worked*, since I could run it from a DOS prompt without errors.  But when I ran it using CreateProcess (and ProcessStartInfo), I didn't see it execute (since it would have created a file in its directory).
>
> However, your answer that I can write it directly with pywin32 intrigues me, especially since I'd rather develop in Python anyway.  I'll go see what's involved in doing that.  Thanks for the pointer!
>



More information about the python-win32 mailing list