[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#859737: ITP: libexecs -- C library for manipulating command strings and executing commands



Package: wnpp
Severity: wishlist

* Package name : libexecs
Version : 1.0
Upstream Author : Renzo Davoli <renzo@cs.unibo.it>
* URL : https://github.com/rd235/s2argv-execs.git
* License : GPL2+
Description : C library for manipulating command strings and executing commands

libexecs is available in two versions, libexecs and libeexecs, where libexecs is the main library and libeexecs is best suited to embedded devices.
It provides the following (classes of) functions:

- s2argv converts a command string into an argv array for execv, execvp, execvpe.

- execs, execsp, execspe are similar to execv(3), execve(2), execvp(3) and execvpe(3), respectively, they take the command line arguments for the file to execute
(and also the command name for execsp(3) and execspe(3)) by parsing a command string args.

- coprocv, coprocvp, coprocvpe, coprocs, coprocsp execute a command in coprocessing mode, versions differ in the way to specify the executable file to run and its parameters.

- esystem, system_eexecsp are 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. The executable file is sought using the PATH environment variable.

- popen_nosh, popen_execsp and pclose_nosh pipe stream to or from a process without using a shell. They are an almost drop in replacement for popen(3) and pclose(3) provided by the libc.

- system_nosh executes a command with its arguments from a string without using a shell. As the popen*/pclose* family of functions for popen(3) and pclose(3), system_nosh is an almost drop in replacement for system(3) provided by the libc.


The following programs show what is possible to do with the given functions (examples with execs and s2argv, respectively):


#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");
    }
}


#include <stdio.h>
#include <unistd.h>
#include <stdlib.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) {
        char **argv=s2argv(buf);
        execvp(argv[0], argv);
        s2argv_free(argv);
        printf("exec error\\n");
    }
}







Reply to: