Python Glossary Русский

all Python 3osfunction

os.spawnle

os — running programs (spawn)

Like spawnl, but with an environment dict as the last argument.

Syntax

os.spawnle(...)

The last argument is the environment dict, and it replaces the environment entirely. On Windows the arguments are joined into one command line, and arguments with spaces may split — subprocess quotes them correctly. The program path must be complete.

Examples

import os
code = os.spawnle(os.P_WAIT, '/bin/sh', 'sh', '-c', 'echo $GREETING', {'GREETING': 'привет'})  # → ? на Unix печатает «привет», в code — 0
code = os.spawnle(os.P_WAIT, '/bin/sh', 'sh', '-c', 'exit 3', {'PATH': '/bin:/usr/bin'})  # → ? на Unix в code — 3, код выхода потомка
code = os.spawnle(os.P_WAIT, '/bin/sh', 'sh', '-c', 'echo $LANG', dict(os.environ, LANG='C'))  # → ? на Unix печатает C: копия os.environ с подменённой переменной
code = os.spawnle(os.P_WAIT, '/bin/sh', 'sh', '-c', 'echo [$HOME]', {})  # → ? на Unix печатает [] — env заменяет окружение целиком, а не дополняет его

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy