From 76472b1bd94cb15fd7f00d3fbde57c703878dab2 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Tue, 21 Apr 2026 11:43:13 +0200 Subject: [PATCH] Use os.startfile() on Windows instead of the start built-in Closes #3164 Co-Authored-By: Adam Karpierz --- CHANGES.rst | 3 +++ src/click/_termui_impl.py | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7f6c9418c..f8422eafd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -29,6 +29,9 @@ Unreleased non-shadowed help option names, so ``Try '... -h'`` no longer points to a subcommand option that shadows ``-h``. All surviving names are shown (``-h/--help``). :issue:`2790` :pr:`3208` +- Use :func:`os.startfile` on Windows to open URLs in :func:`open_url`, + replacing the ``start`` built-in which cannot be invoked without + ``shell=True``. :issue:`3164` :pr:`3186` Version 8.3.3 ------------- diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py index c9f1e1c53..3ceef748d 100644 --- a/src/click/_termui_impl.py +++ b/src/click/_termui_impl.py @@ -720,17 +720,16 @@ def _unquote_file(url: str) -> str: if locate: url = _unquote_file(url) args = ["explorer", f"/select,{url}"] + try: + return subprocess.call(args) + except OSError: + return 127 else: - args = ["start"] - if wait: - args.append("/WAIT") - args.append("") - args.append(url) - try: - return subprocess.call(args) - except OSError: - # Command not found - return 127 + try: + os.startfile(url) # type: ignore[attr-defined] + except OSError: + return 127 + return 0 elif CYGWIN: if locate: url = _unquote_file(url)