all Python 3osfunction
os.spawnve
os — running programs (spawn)
Like spawnv, but with an explicit environment dict.
Syntax
os.spawnve(...)
As with execve, the environment is replaced entirely: without PATH, HOME and LANG the program will not get them. The program path must be complete. To run with a modified environment subprocess.run(args, env={**os.environ, ...}) is handier.
Examples
import os
import sys
env = {**os.environ, 'GREETING': 'hello'} # env заменяет окружение целиком, поэтому его копируют из os.environ
print(env['GREETING']) # → hello
print(os.spawnve(os.P_WAIT, sys.executable, ['python', '-c', 'import os; print(os.environ["GREETING"])'], env)) # → сначала потомок печатает hello, затем 0 — код выхода
print('PATH' in os.environ) # → True
print('PATH' in {'GREETING': 'hello'}) # → False (с таким «голым» env дочерний процесс останется без PATH)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy