0

I am reading "Programming Python" 4e and on Page182 there is this line of code:

os.execlp('python', 'python', 'child.py', str(parm))

The purpose of the code is to run the script 'child.py'. However, I do not understand why there are two 'python's in the argument list. I believe that execlp take arguments like execlp(program, cmdarg1, cmadarg2,... cmdargN). So here the first 'python' is the program, that's ok; but what is the second 'python' for? If that's an argument, then we are basically running "python python child.py" and that does not make sense.

Actually I tried to use:

os.execlp('python', 'child.py', str(parm))

instead, but the result was that a new instance of python environment is launched without running the 'child.py' script.

So, how should I interpret the two 'python's in the argument list?

mulog
  • 11
  • 1
  • 1
  • Try here: http://stackoverflow.com/questions/13439938/execlp-in-python or this one: http://stackoverflow.com/questions/14174366/when-using-os-execlp-why-python-need-python-as-argv0/14174423#14174405 – Andrew Ehrlich Oct 16 '13 at 02:51
  • 2
    FYI `exec()` is something else entirely, as I'm sure at least one poster came in prepared to tell you (and how you should never use it) – roippi Oct 16 '13 at 02:54
  • @Yohann thank you for the link, that solved my question. Have no idea how I missed that when searching:( – mulog Oct 16 '13 at 14:10

0 Answers0