system_nosh(3) | Linux Programmer's Manual | system_nosh(3) |
esystem, system_eexecsp - execute a command with its arguments from a string without using a shell
#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.
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).
These functions have the same return values of system(3).
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"); } }
Bug reports should be addressed to <info@virtualsquare.org>
Renzo Davoli <renzo@cs.unibo.it>
2014-05-27 | VirtualSquare |