Python Glossary Русский

all Python 3Linux · macOSosfunction

os.spawnvpe

os — running programs (spawn)

Like spawnvp, but with an explicit environment dict.

Syntax

os.spawnvpe(...)

It combines PATH lookup, a list of arguments and a new environment, and is unavailable on Windows. The environment is replaced entirely. All spawn* variants are a historical interface; subprocess covers their abilities and adds output capture and timeouts.

Examples

import os
env = {**os.environ, 'LANG': 'C'}   # p-форма ищет программу в PATH, e-форма берёт окружение из env
print(env['LANG'])   # → ? C
code = os.spawnvpe(os.P_WAIT, 'env', ['env'], env)   # → ? только Unix: печатает переменные окружения, code == 0
pid = os.spawnvpe(os.P_NOWAIT, 'sleep', ['sleep', '5'], env)   # → ? только Unix: сразу возвращает идентификатор процесса, например 12345
print('PATH' in {'LANG': 'C'})   # → False: с таким env поиск пойдёт по os.defpath, а не по вашему PATH

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy