Python Glossary Русский

all Python 3osfunction

os.spawnl

os — running programs (spawn)

Like spawnv, but with inline arguments.

Syntax

os.spawnl(...)

Arguments are listed inline after the mode and path, and the first is again the program name: spawnl(os.P_WAIT, '/bin/ls', 'ls', '-l'). Omitting the name is a common mistake that costs the program its first argument. New code should use subprocess.

Examples

import os
print(os.P_WAIT, os.P_NOWAIT)  # → ? 0 1 — режимы: дождаться потомка или сразу вернуть PID
code = os.spawnl(os.P_WAIT, '/bin/echo', 'echo', 'привет')  # → ? на Unix печатает «привет», в code — код выхода потомка (0)
pid = os.spawnl(os.P_NOWAIT, '/bin/sleep', 'sleep', '1')  # → ? на Unix не ждёт завершения и возвращает PID потомка, например 12345
os.spawnl(os.P_WAIT, '/bin/echo', 'привет')  # → ? печатает пустую строку: первый аргумент после пути — это argv[0] (имя программы), а не данные

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy