Python Glossary Русский

all Python 3Linux · macOSosfunction

os.spawnvp

os — running programs (spawn)

Like spawnv, but the program is looked up in PATH.

Syntax

os.spawnvp(...)

It searches PATH and takes arguments as a list with the program name first. It is unavailable on Windows. With P_NOWAIT remember to reap the child with waitpid, or on Unix it stays a zombie until the parent exits.

Examples

import os
print('PATH' in os.environ)   # → ? True: именно в PATH spawnvp ищет программу по имени
code = os.spawnvp(os.P_WAIT, 'echo', ['echo', 'hi'])   # → ? только Unix: печатает hi, code == 0
pid = os.spawnvp(os.P_NOWAIT, 'sleep', ['sleep', '5'])   # → ? только Unix: не ждёт, возвращает идентификатор процесса, например 12345
print(os.path.basename('/bin/echo'))   # → ? echo: spawnvp хватит имени, а spawnv потребовал бы полный путь

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy