From 709e0bd67aa0b8b888e4ab0b34f71ea5dbe14bf2 Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Mon, 19 Feb 2024 14:55:08 +0200 Subject: [PATCH 1/2] ulwlg_run.py: Capture and return the exit code of the subprocess * Return the exitcode of the subprocess from `main` in case the caller wants to do something this it. * Catch any exceptions during execution and return an error exitcode. --- ulwgl_run.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ulwgl_run.py b/ulwgl_run.py index 801b675..6681545 100755 --- a/ulwgl_run.py +++ b/ulwgl_run.py @@ -2,6 +2,7 @@ import os import argparse +from traceback import print_exception from argparse import ArgumentParser, Namespace import sys from pathlib import Path @@ -281,7 +282,7 @@ def build_command( return command -def main() -> None: # noqa: D103 +def main() -> int: # noqa: D103 env: Dict[str, str] = { "WINEPREFIX": "", "GAMEID": "", @@ -327,8 +328,12 @@ def main() -> None: # noqa: D103 os.environ[key] = val build_command(env, command, opts) - subprocess.run(command) + return subprocess.run(command).returncode if __name__ == "__main__": - main() + try: + sys.exit(main()) + except Exception as e: # noqa: BLE001 + print_exception(e) + sys.exit(1) From ffd22ca1a14e2ab999b9470ed7011d3d5a4b2fce Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Mon, 19 Feb 2024 15:01:45 +0200 Subject: [PATCH 2/2] ulwg_run.py: print to `stderr` only * Avoid polluting `stdout` since the caller might expect the output of the command there. --- ulwgl_run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ulwgl_run.py b/ulwgl_run.py index 6681545..d744c39 100755 --- a/ulwgl_run.py +++ b/ulwgl_run.py @@ -35,13 +35,13 @@ example usage: if not sys.argv[1:]: err: str = "Please see project README.md for more info and examples.\nhttps://github.com/Open-Wine-Components/ULWGL-launcher" - parser.print_help() + parser.print_help(sys.stderr) raise SystemExit(err) if sys.argv[1:][0] in opt_args: return parser.parse_args(sys.argv[1:]) - return (sys.argv[1], sys.argv[2:]) + return sys.argv[1], sys.argv[2:] def setup_pfx(path: str) -> None: