execse3
Execute a file taking its arguments from a string
Part of execs(3).
Usage
int execs(const
char
*path,
const
char
*args);
int execse(const
char
*path,
const
char
*args,
char
*const
envp
[]
);
int execsp(const
char
*args);
int execspe(const
char
*args,
char
*const
envp
[]
);
int eexecs(const
char
*path,
char
*args);
int eexecse(const
char
*path,
char
*args,
char
*const
envp
[]
);
int eexecsp(char
*args);
int eexecspe(char
*args,
char
*const
envp
[]
);
Overview
This group of functions extends the family of exec(3) provided by the libc.
execs, execse, execsp and execspe are similar to execv(3), execve(2), execvp(3) and execvpe(3), respectively, but take the command line arguments for the file to execute (and the also the command name for execsp(3) and execspe(3)) by parsing a command string args.
Command arguments in args are delimited by space characters (blank, tabs or new lines). Single or double quotes can be used to delimitate command arguments including spaces and a non quoted backslash (\) is the escape character to protect the next char.
execs, execse, execsp and execspe do not use dynamic allocation but require space on the stack to store an entire copy of args. eexecs, eexecse, eexecsp and eexecspe do not use extra stack space but modify args.
In case the same argv should be used for several exec command, use s2argv(3) to parse the args just once.
Return value
These functions return only if an error has occurred. The return value is always -1. The failure cases and errno values are those specified for execve(2).
Examples
The following program demonstrates the use of execs:
#include <stdio.h>
#include <unistd.h>
#include <execs.h>
#define BUFLEN 1024
int main(int argc, char *argv)
{
char buf[BUFLEN];
printf("type in a command and its arguments, e.g. 'ls -l'\n");
if (fgets(buf, BUFLEN, stdin) != NULL) {
execsp(buf);
printf("exec error\n");
}
}