views:

36

answers:

1

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?

+2  A: 

UNIX, where all these exec things 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 first 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):

execl ("/usr/bin/sleep", "notsleep", "60", NULL);

This would run the program /usr/bin/sleep but it would show up in the process list as notsleep. argv[0] would be notsleep and argv[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 you list is (seemingly) ignored. It's the name to give to the process, not the first argument to it.

paxdiablo