Go---the use of the Python os.exec* () family function

Source: Internet
Author: User

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 intmain(intargc, char** argv)         inti;         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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.