Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing arguments to a python service
    text
    copied!<p>I need some help with a python service.</p> <p>I have a service written in Python. What I need to do is to pass it some arguments. Let me give you an example to explain it a bit better.</p> <p>Lets say I have a service, that does nothing but writes something to a log. I'd like to write the same thing into the log several times, so I use a loop. I would like to pass the counter for the loop when I start the service, but I have no idea how. I start the service with:</p> <pre><code>win32serviceutil.HandleCommandLine(WinService) </code></pre> <p>I'm looking for something like </p> <pre><code>win32serviceutil.HandleCommandLine(WinService,10) </code></pre> <p>I don't really care how its done, as long as I can pass arguments to it. Have been trying to get this to work for the better part of the day with no luck. Also, the service isn't run directly, but is imported and then run from there. </p> <p>EDIT:</p> <p>Here is an example, hopefully it will clear some things up.</p> <p>This is in WindowsService.py:</p> <pre><code>import win32serviceutil, win32service, win32event, servicemanager, win32serviceutil class LoopService(win32serviceutil.ServiceFramework): _svc_name_ = "LoopService" _svc_description_ = "LoopService" _svc_display_name_ = "LoopService" def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop = win32event.CreateEvent(None,0,0,None) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING); win32event.SetEvent(self.hWaitStop); def SvcDoRun(self): i = 0; while i &lt; 5: servicemanager.LogInfoMsg("just something to put in the log"); i += 1 win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) </code></pre> <p>This is in the main script:</p> <pre><code>import service.WindowsService, win32serviceutil win32serviceutil.HandleCommandLine(service.WindowsService.LoopService); </code></pre> <p>As it is now, the loop will execute a fixed amount of times. What I would like is to simply send the value to the service somehow. Don't really care how.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload