From the python docs:
The various exec*() functions take a
list of arguments for the new program
loaded into the process. In each case,
the first of these arguments is passed
to the new program as its own name
rather than as an argument a user may
have typed on a command line. For the
C programmer, this is the argv[0]
passed to a program’s main(). For
example, os.execv(‘/bin/echo’, [‘foo’,
‘bar’]) will only print bar on
standard output; foo will seem to be
ignored.
Can someone please help me understand this? What do I need to do if I want to run my own program with some parameters?
UNIX, where all these
execthings come from, separated the program executable file from the program name, so that your process could have any arbitrary name.The first argument is the program that will run. This must exist. The next argument is what your process running the program will be called, what will be in
argv[0], and what comes up in theps(process list) output.So, if I did (in C, but it maps to Python as well):
This would run the program
/usr/bin/sleepbut it would show up in the process list asnotsleep.argv[0]would benotsleepandargv[1](the actual argument) would be 60. Often, the first two parameters will be identical but it’s by no means required.That’s why the first argument of your list is (seemingly) ignored. It’s the name to give to the process, not the first argument to it.
A more correct way to do it would be: