问题
This is very frustrating. I am trying to launch any EXE from a WINDOWS SERVICE. I'm using Python 3.5 and Win10. I created the service inheriting from win32serviceutil.ServiceFramework
as I have seen in many examples on the Internet
I've tried it with os.startfile()
, subprocess.call()
, subprocess.Popen()
and os.system()
and always with the same result. The application's executable (that I launched from the service) is appearing as a subthread (subprocess) no like main process and you don't see any windows (GUI).
It doesn't matter if it's a program compiled by me or any executable like Windows Notepad.exe
def main(self):
while self.isrunning:
try:
# Check if subprocess exists:
s = subprocess.check_output('tasklist', shell=True)
if bytes("notepad.exe", 'UTF-8') not in s:
os.startfile('notepad.exe')
And I've also tried:
os.startfile('notepad.exe')
results = subprocess.Popen(['notepad.exe'], close_fds=True, creationflags=DETACHED_PROCESS)
subprocess.Popen('notepad.exe')
and in the other ways that I mentioned before. Same result.
The application runs like subprocess (the thread is running in the TaskManager Subprocess section) but no window is visible.
If I run the same code from a normal Python script it works perfect. The problem is doing it from the service.
Some help? Thanks in advance.
来源:https://stackoverflow.com/questions/57808197/how-can-i-run-an-exe-file-from-python-3-x-windows-service