Skip to content

Commit d04d367

Browse files
kdeldyckekarpierz
andcommitted
Use os.startfile() on Windows instead of the start built-in
Closes #3164 Co-Authored-By: Adam Karpierz <akarpierz@gmail.com>
1 parent f1f191e commit d04d367

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Version 8.3.3
55

66
Unreleased
77

8+
- Use :func:`os.startfile` on Windows to open URLs in :func:`open_url`,
9+
replacing the ``start`` built-in which cannot be invoked without
10+
``shell=True``. :issue:`3164` :pr:`3186`
811
- Use :func:`shlex.split` to split pager and editor commands into ``argv``
912
lists for :class:`subprocess.Popen`, removing ``shell=True``.
1013
:issue:`1026` :pr:`1477` :pr:`2775`

src/click/_termui_impl.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,17 +720,16 @@ def _unquote_file(url: str) -> str:
720720
if locate:
721721
url = _unquote_file(url)
722722
args = ["explorer", f"/select,{url}"]
723+
try:
724+
return subprocess.call(args)
725+
except OSError:
726+
return 127
723727
else:
724-
args = ["start"]
725-
if wait:
726-
args.append("/WAIT")
727-
args.append("")
728-
args.append(url)
729-
try:
730-
return subprocess.call(args)
731-
except OSError:
732-
# Command not found
733-
return 127
728+
try:
729+
os.startfile(url) # type: ignore[attr-defined]
730+
except OSError:
731+
return 127
732+
return 0
734733
elif CYGWIN:
735734
if locate:
736735
url = _unquote_file(url)

0 commit comments

Comments
 (0)