Skip to content

subprocess.run(..., env={}) broken on Windows #105436

Description

@mandolaerik

Bug report

When passing an empty dictionary as env to subprocess.run (or Popen), I get the following error:

Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run('c:\\msys64\\usr\\bin\\echo.exe', env={})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jhbaarnh\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jhbaarnh\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\jhbaarnh\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1509, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 87] The parameter is incorrect
>>>

Environment

  • Reproduced on the following CPython versions, all native windows builds:
    • vanilla python 3.11.3
    • vanilla Python 3.9.6
    • Intel Python 3.9.16
  • I can not reproduce the problem on any of the following:
    • python 3.7.2, native Windows build and MSYS build (did not try newer MSYS)
    • any linux

Linked PRs

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixesOS-windowsextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions