all Python 3osfunction
os.spawnv
os — running programs (spawn)
Runs a new program (a path plus an argument list) in a separate process; returns the PID or the exit code depending on the mode.
Syntax
os.spawnv(...)
The result depends on the mode: with P_WAIT it is the program's exit code, with P_NOWAIT a PID you must later reap with waitpid. The first list item is the program name. This is an old interface; the documentation recommends subprocess, which offers output capture, timeouts and clear errors.
Examples
import os
import sys
args = ['python', '-c', 'pass'] # argv[0] — имя программы, дальше её аргументы
print(os.spawnv(os.P_WAIT, sys.executable, args)) # → 0
pid = os.spawnv(os.P_NOWAIT, sys.executable, args)
print(pid > 0) # → True (P_NOWAIT не ждёт: сразу отдаёт идентификатор запущенного процесса)
print(os.spawnv(os.P_WAIT, sys.executable, [])) # → ValueError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy