python / python/cpython

`subprocess.run` docs should recommend copying `os.environ` on Windows

Abierto
#120,836 5 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

docs topic-subprocess
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

As described in https://stackoverflow.com/questions/78652758/, when passing custom environment variables to subprocess.run or subprocess.Popen on Windows, you will usually need to include the existing keys from os.environ in order to reliably run arbitrary processes (exactly which keys are required to be present depends on what the subprocess is doing).

The subprocess.Popen docs include a "Note" about this problem, but the subprocess.run docs omit it. Even the subprocess.Popen note is a bit vague, and only specifically mentions SystemRoot:

Note: If specified, env must provide any variables required for the program to execute. On Windows, in order to run a side-by-side assembly the specified env must include a valid SystemRoot.

The common documentation for the env parameter reads:

If env is not None, it must be a mapping that defines the environment variables for the new process; these are used instead of the default behavior of inheriting the current process’ environment. It is passed directly to Popen. This mapping can be str to str on any platform or bytes to bytes on POSIX platforms much like os.environ or os.environb.

Rather than re-using the existing subprocess.Popen note, my suggestion would be to add the following sentence to the above paragraph:

On Windows, many applications require specific environment variables (such as SystemRoot) to be set as expected in order to work correctly. Accordingly, it is recommended to start from os.environ.copy() when customing the subprocess environment on Windows, rather than starting from an empty dictionary (otherwise the executed subprocesses may fail with various Windows OS errors).

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la documentación compartida del parámetro env para subprocess.run y subprocess.Popen; después, compara la nota existente sobre Windows en la documentación de Popen. Añade orientación para comenzar con os.environ.copy() al personalizar el entorno de un subprocess en Windows y verifica que la redacción actualizada cubra claramente las variables requeridas, como SystemRoot.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.