'popen'에 해당되는 글 1건

  1. 2013.10.23 popen 보기 c

popen 보기 c

카테고리 없음 2013. 10. 23. 14:21

#include <stdio.h>

#include <stdlib.h>

#include <strings.h>

#include <unistd.h>

int main ()

{

        FILE *fp;

        char buf[1024];

        char *token;

        int cnt;



        fp = popen("/usr/bin/wc -l abc.txt", "r");

        if (fp == NULL)

        {

                printf("ERROR:popen fail\n");

                exit(0);

        }

        fread(buf, 1, 1024, fp);

        pclose(fp);


        printf("buf:%s\n", buf);

        token = (char *) strtok(buf, " ");

        printf("token:%s\n", token);

        cnt = atoi(token);


        printf("cnt:%d\n", cnt);


}