C language Execl () function: Performing file functions
header file:
To define a function:
int execl (const char * path, const char * arg, ...);
Function Description: The EXECL () is used to execute the path of the file represented by the parameter path string, and the next argument represents the passing of the past argv (0), argv[1] When the file is executed, the last argument must end with a null pointer (NULL).
Return value: If the execution succeeds then the function does not return, the execution fails to return 1 directly, and the reason for failure is in errno.
Example
#include <unistd.h>
Main ()
{
execl ("/bin/ls", "ls", "-al", "/etc/passwd", (char *) 0);
Perform:
/* Execute/BIN/LS-AL/ETC/PASSWD */
-rw-r--r--1 root 705 Sep 3 13:52/etc/passwd
C language EXECLP () function: Find files from the PATH environment variable and execute
header file:
To define a function:
int EXECLP (const char * file, const char * arg, ...);
Function Description: EXECLP () looks up the filename of the parameter file from the directory referred to in the PATH environment variable, executes the file after it is found, and then takes the second parameter as the argv[0 of the file, Argv[1], ..., the last argument must have a null pointer (NULL) End.
Return value: If the execution succeeds then the function does not return, the execution fails to return 1 directly, and the reason for failure is in errno.
Error code: Reference Execve ().
Example
/* Execution ls-al/etc/passwd EXECLP () will find/bin/ls/
#include <unistd.h>
main ()
{
EXECLP according to the/bin in the PATH variable ("ls", "ls", "-al", "/etc/passwd", (char *) 0);
}
Perform:
-rw-r--r--1 root 705 Sep 3 13:52/etc/passwd