Arguments to exec* functions.

Michael Hudson mwh21 at cam.ac.uk
Mon Nov 13 21:35:19 CET 2000


cerutti at together.net (Neil Cerutti) writes:

> Michael Hudson posted:
> >cerutti at together.net (Neil Cerutti) writes:
> >
> >> Am I required to pass the name and path of the executable as the
> >> first item in the tuple or list of arguments to an exec*()
> >> function? I know some programs depend on the name of the
> >> executable for functional changes, e.g., gzip.
> >
> >On my system:
> >
> >$ ls --inode /bin/*zip
> >  30165 /bin/gunzip    30165 /bin/gzip
> >
> >i.e. "gzip" and "gunzup" actually are the same file, so the
> >executable needs some way to tell which is was invoked as -
> >hence argv[0].
> 
> Yes, I understand that. But why can't the os module extrapolate
> it for me, instead of forcing me to do it manually?
> 
> Fredrik Lundh says it follows the POSIX standard; that explains
> the semantics of argv, but it doesn't explain why the os module
> wraps it this way. Is it often useful to run a process and lie to
> it about its own name?

Not sure about "often", but try these:

>>> os.execl("/bin/bash","bash")
>>> os.execl("/bin/bash","-bash")

... but bascially it's because that's the way C does it, and that's
the general pattern for Python exposing C api's (and I personally
quite like it that way).

Cheers,
M.

-- 
  /* I'd just like to take this moment to point out that C has all
     the expressive power of two dixie cups and a string.
   */                       -- Jamie Zawinski from the xkeycaps source



More information about the Python-list mailing list