Logo Search packages:      
Sourcecode: fakechroot version File versions  Download package

test-popen.c

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

#include <errno.h>

#ifndef PATH_MAX
#define PATH_MAX 2048
#endif


int main (int argc, char *argv[]) {
    FILE *fp;
    int status;
    char path[PATH_MAX];

    if (argc != 2) {
        fprintf(stderr, "Usage: %s cmd\n", argv[0]);
        exit(2);
    }

    fp = popen(argv[1], "r");
    if (fp == NULL) {
        perror("popen");
        exit(1);
    }

    while (fgets(path, PATH_MAX, fp) != NULL) {
        printf("%s", path);
    }

    status = pclose(fp);
    if (status == -1) {
        perror("pclose");
        exit(1);
    }
}

Generated by  Doxygen 1.6.0   Back to index