title: Popen fails to start a process when I call it from a python script that runs as service in windows
body: <p>My service calls subprocess.Popen(CMD) to start Everything when Everything not running. The commain line works well in windows shell or command, but not in service, is there something I missed?</p>
  <p>I found another answer said it's a CWD problem in a similar question, don't
  get it. <a href="https://stackoverflow.com/questions/57647539/popen-fails-to-start-a-process-when-i-call-it-from-a-python-script-that-runs-as">Popen fails to start a process when I call it from a python script that runs as a Linux service</a></p>
  <pre><code>class DetectorService(win32serviceutil.ServiceFramework):
  _svc_name_ = &quot;Detector&quot;
  _svc_display_name_ = &quot;DetectorService&quot;
  _svc_description_ = &quot;DetectorService&quot;
  
  def __init__(self, args):
      win32serviceutil.ServiceFramework.__init__(self, args)
      self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
      socket.setdefaulttimeout(60)
  
  def SvcStop(self):
      self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
      win32event.SetEvent(self.hWaitStop)
  
  def SvcDoRun(self):
      rc = None
      while rc != win32event.WAIT_OBJECT_0:
          cmd = 'C:\\abspath\\Everything.exe -minimized -regex -close'
          subprocess.Popen(cmd,shell=False,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL)
          rc = win32event.WaitForSingleObject(self.hWaitStop, 1000)
  
  if __name__ == '__main__':
      if len(sys.argv) == 1:
          servicemanager.Initialize()
          servicemanager.PrepareToHostSingle(DetectorService)
          servicemanager.StartServiceCtrlDispatcher()
      else:
          win32serviceutil.HandleCommandLine(DetectorService)
  </code></pre>