jeudi 1 janvier 2015

Why do I get an error trying to install my Python service in Windows?


Vote count:

0




Ok so I scripted a python service that simply writes to a file. I packaged it all up with cx_freeze, and installed it as a Service via the command prompt. It ran fine, but then I realized that the file it was to writing was in some weird directory, so I changed the service code to write to my documents. Here's the code for my Python Service:



import win32service
import win32serviceutil
import win32event

class PySvc(win32serviceutil.ServiceFramework):
_svc_name_ = "PySvc"
_svc_display_name_ = "Python Test Service"
_svc_description_ = "This is a service that simply writes to a file"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcDoRun(self):
import servicemanager
f = open('C:/Users/Luke/Documents/test.dat', 'w+')
rc = None

while rc != win32event.WAIT_OBJECT_0:
f.write('TEST DATA\n')
f.flush()
rc = win32event.WaitForSingleObject(self.hWaitStop, 5000)

f.write('SHUTTING DOWN...\n')
f.close()

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

if __name__ == '__main':
win32serviceutil.HandleCommandLine(PySvc)


This time when I attempted to install it in the cmd, it returned this frustrating error:



Exception occurred while initializing the installation:System.BadImageFormatException: Could not load file or assembly 'http://file/C:\PySvc\PySvc.exe' or one of its dependencies. The module was expected to contain an assembly manifest..


What Happened? Any Help?



asked 6 mins ago







Why do I get an error trying to install my Python service in Windows?

Aucun commentaire:

Enregistrer un commentaire