import os import sys pid = os.fork() print ("second test") if pid == 0: print ("this is the child") print ("I'm going to exec another program now") os.execl("python", "test.py", * sys.argv) else: print ("the child is pid %d" % pid) os.wait() I've looked everywhere at examples, but for the life of me, I just can't understand it whatsoever. I thought this would work, but I get this error:
Traceback (most recent call last): File "main.py", line 9, in <module> os.execl("python", "test.py", * sys.argv) File "/usr/local/lib/python3.8/os.py", line 534, in execl execv(file, args) FileNotFoundError: [Errno 2] No such file or directory
execldoesn't do path lookup.subprocessinstead if you are forking just to callexeclin the child process.