diff --git a/SABnzbd.py b/SABnzbd.py index 24ef7639d0c..4ff86dfa1c8 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -860,7 +860,7 @@ def main(): ipv6_hosting = None inet_exposure = None - service, sab_opts, _serv_opts, upload_nzbs = commandline_handler() + _service, sab_opts, _serv_opts, upload_nzbs = commandline_handler() for opt, arg in sab_opts: if opt == "--servicecall": @@ -949,8 +949,9 @@ def main(): sabnzbd.DIR_LANGUAGE = real_path(sabnzbd.DIR_PROG, DEF_LANGUAGE) org_dir = os.getcwd() - # Need console logging if requested or just running as script - console_logging = (console_logging or not hasattr(sys, "frozen")) and not sabnzbd.DAEMON + # Need console logging if requested, for SABnzbd.py and SABnzbd-console.exe + console_logging = console_logging or sys.executable.endswith("console.exe") or not hasattr(sys, "frozen") + console_logging = console_logging and not sabnzbd.DAEMON LOGLEVELS = (logging.FATAL, logging.WARNING, logging.INFO, logging.DEBUG) @@ -1639,6 +1640,12 @@ class SABnzbd(win32serviceutil.ServiceFramework): "access to network shares." ) + # Only SABnzbd-console.exe can print to the console, so the service is installed + # from there. But we run SABnzbd.exe so nothing is logged. Logging can cause the + # Windows Service to stop because the output buffers are full. + if hasattr(sys, "frozen"): + _exe_name_ = "SABnzbd.exe" + def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) diff --git a/builder/SABnzbd.spec b/builder/SABnzbd.spec index 6617003b2bf..72d6e61ed59 100644 --- a/builder/SABnzbd.spec +++ b/builder/SABnzbd.spec @@ -113,8 +113,7 @@ exe = EXE( [], exclude_binaries=True, name="SABnzbd", - console=True, - hide_console="hide-early", + console=False, append_pkg=False, icon="icons/sabnzbd.ico", contents_directory=".", @@ -126,6 +125,29 @@ exe = EXE( coll = COLLECT(exe, pyi_analysis.binaries, pyi_analysis.zipfiles, pyi_analysis.datas, name="SABnzbd") +# We need to run again for the console-app +if sys.platform == "win32": + # Enable console=True for this one + console_exe = EXE( + pyz, + pyi_analysis.scripts, + [], + exclude_binaries=True, + name="SABnzbd-console", + append_pkg=False, + icon="icons/sabnzbd.ico", + contents_directory=".", + version=version_info, + ) + + console_coll = COLLECT( + console_exe, + pyi_analysis.binaries, + pyi_analysis.zipfiles, + pyi_analysis.datas, + name="SABnzbd-console", + ) + # Build the APP on macOS if sys.platform == "darwin": info_plist = { diff --git a/builder/package.py b/builder/package.py index 352a6423e9a..9ece063fe34 100644 --- a/builder/package.py +++ b/builder/package.py @@ -227,6 +227,9 @@ def test_sab_binary(binary_path: str): # Run PyInstaller and check output run_external_command([sys.executable, "-O", "-m", "PyInstaller", "SABnzbd.spec"]) + shutil.copytree("dist/SABnzbd-console", "dist/SABnzbd", dirs_exist_ok=True) + safe_remove("dist/SABnzbd-console") + # Remove unwanted DLL's shutil.rmtree("dist/SABnzbd/Pythonwin") if BUILDING_64BIT: