简体   繁体   中英

py2exe: How do I hide the console window for a service

This is my setup.py

class Target:
  def __init__(self, **kw):
    self.__dict__.update(kw)

myservice = Target(
  description = 'My App',
  modules = ['main'],
  cmdline_style='pywin32',
)

setup(
  name = 'MyApp',
  service = [myservice],
  version = '0.1.0.0'
)

I know that there are many sources that explain how to hide the console on py2exe, but I haven't seen one that explains how to hide the console of a service.
When I run my app as a service then no console appears.
But when I run my app regularly by double clicking then it shows the console window.
I need the app to run both as a service and a normal process without a console window.
How could I achieve this?

py2exe doesn't provide a configuration flag to do it, but you can monkey patch it with these lines in setup.py:

from py2exe import build_exe
build_exe.py2exe.get_service_template = build_exe.py2exe.get_windows_template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM