Skip to content

fix: use os.startfile on Windows instead of subprocess start#3320

Closed
MAXDVVV wants to merge 1 commit intopallets:mainfrom
MAXDVVV:fix/launch-windows-2868
Closed

fix: use os.startfile on Windows instead of subprocess start#3320
MAXDVVV wants to merge 1 commit intopallets:mainfrom
MAXDVVV:fix/launch-windows-2868

Conversation

@MAXDVVV
Copy link
Copy Markdown

@MAXDVVV MAXDVVV commented Apr 6, 2026

Problem

click.launch("https://example.com") fails on Windows with [WinError 2] The system cannot find the file specified since version 8.1.8.

This is because start is a Windows shell built-in command, not an executable file. The migration from os.system() to subprocess.call() in #1477 broke this — subprocess.call(["start", ...]) requires shell=True to work, but the maintainers correctly don't want to use shell=True.

Fix

Replace subprocess.call(["start", ...]) with os.startfile(), which is the native Python API for opening files and URLs on Windows. It calls the Windows ShellExecuteW API directly without needing a shell.

  • Non-locate case: Uses os.startfile(url) directly
  • Locate case: Keeps subprocess.call(["explorer", "/select,..."]) (explorer.exe is a real executable)
  • Fallback: If os.startfile fails with OSError, falls back to webbrowser.open() for HTTP(S) URLs (same pattern as the Linux/xdg-open fallback)

Test

Added test_open_url_windows_uses_startfile — monkeypatches os.startfile and verifies it's called with the URL.

Fixes #2868

On Windows, 'start' is a shell built-in command, not an executable.
subprocess.call(['start', ...]) without shell=True fails with
'[WinError 2] The system cannot find the file specified'.

Replace with os.startfile() which is the native Python API for
opening files/URLs on Windows. Add webbrowser.open fallback for
HTTP(S) URLs if startfile fails.

Fixes pallets#2868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: click.launch() broken on Windows in version 8.1.8

2 participants