python os.execv* bug
Bug #174830 reported by
Joe_Bishop
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-defaults (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: python
Two python executables, main and prog:
>main:
>#!/usr/bin/env python
>#coding=utf8
>
>import os
>os.execvp(
>prog:
>#!/usr/bin/env python
>#coding=utf8
>
>import sys
>print sys.argv
./main gives output:
>['./prog', 'b', 'c', 'd', 'e']
although
>['./prog', 'a', 'b', 'c', 'd', 'e']
is expected
To post a comment you must log in.
it looks correct to me. argv[0] of the underlying os call execve is the first argument given to the process that is being run, which is how you can run a symlink to a program and have the binary image be FOO but argv[0] be BAR.
So 'a' is passed in to execv, and then an additional redirection occurs where the #! line is evaluated, and the new image of /usr/bin/env is chosen, - man execve explains this. So the final thing executed is
[/usr/bin/env python b c d e] with a argv[0] of 'a', but then it exec's again to run python.