Execl (file, arg0,arg1,...) Execute file with parameter list arg0, arg1, etc.
Execv (file, arglist) in addition to using a list of parameter vectors, the other is the same as EXECL ()
Execle (file, Arg0,arg1,... env) and execl are the same but provide an environment variable dictionary env
Execve (file,arglist, env) except with a list of parameter vectors, the others are the same as execle ()
EXECLP (cmd, arg0,arg1,...) is the same as execl (), but searches the user's search path for a full file path name
EXECVP (cmd, arglist) In addition to a list of parameter vectors, same as EXECLP ()
Execlpe (cmd, arg0, arg1,... env) and EXECLP are the same but provide an environment variable dictionary env
EXECVPE (Cmd,arglist, env) and EXECVP are the same but provide an environment variable dictionary env
Usage:
Os.execl ("/usr/bin/python", "test.py", "I") is not a good way to write,
To do this
Os.execl ("/usr/bin/python", "Python", ' test.py ', ' I ')
Os.exec* () is just a direct mapping of the POSIX system, so Os.execl's first argument "/usr/bin/python" is the program's executable, while the others are programs argument, which is the C int main (int argc , char** argv) in the argv.
Python's sys.argv should be argv [1:] in C, so the second parameter in os.execl "Python" is not visible to the Python program test.py and is useless.
In fact, the second argument of Os.execl, the argv[0 in int main (int argc,char** argv), can be arbitrary, which is essentially supplied to the C program as the first parameter of the main () function.
For example, you write a C program as follows.
12345678 |
int
main(
int
argc,
char
** argv)
{
int
i;
for
(i=0; i<argc; i++)
{
printf
(
"%d--%s\n"
, i, argv[i]);
}
}
|
Compile into AAA
If you do it alone
/PATH/TO/AAA BBB CCC
This will print
0--/path/to/aaa
1--bbb
2--ccc
Actually the shell executes Execl ("/path/to/aaa", "/path/to/aaa", "BBB", "CCC") set Argv[0] to/PAT/TO/AAA.
A misunderstanding is that the second parameter in EXECL must be the program name of "/path/to/aaa", but it is not.
And with
Os.execl ("/path/to/aaa", "TTT", ' BBB ', ' CCC ')
The print
0--ttt
1--bbb
2--ccc
Go---the use of the Python os.exec* () family function