system_eexecsp3
Execute a command with its arguments from a string without using a shell
Part of esystem(3).
Usage
#include <stdlib.h>
#include <execs.h>
int esystem(const char *command);
int system_eexecsp(const char *command);
These functions are provided by libexecs and libeexecs. Link with -lexecs or -leexecs.
Overview
esystem is an almost drop in replacement for system(3) provided by the libc. esystem parses the command string and runs the command directly, without using a shell. (system_eexecsp and esystem are synonyms).
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. The executable file is sought using the PATH environment variable as explained for execlp(3).
Return value
These functions have the same return values of system(3).
Examples
The following program shows the usage of esystem:
#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");
while (fgets(buf, BUFLEN, stdin) != NULL) {
printf("Command: '%s' \n",buf);
esystem(buf);
printf("Command done\n");
}
}
Releases
Unchanged in 4 releases since Debian 10 (Buster).