리눅스 파이프 관련
글쓴이: imggr / 작성시간: 화, 2011/11/22 - 3:58오후
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <math.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include <unistd.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> /* ls -l | od -c | wc > out.txt */ #define MAX_LINE 100 //############################################################################# int main(int argc, char **argv) { int res, i; if (argc != 1) { printf("USAGE: ] ./ret \n"); exit(0); } int data_processed; int file_pipes[2]; pid_t fork_result; if (pipe(file_pipes) == 0) { fork_result = fork(); if (fork_result == (pid_t)-1) { fprintf(stderr, "Fork failure"); exit(EXIT_FAILURE); } if (fork_result == (pid_t)0) { close(0); dup(file_pipes[0]); close(file_pipes[0]); close(file_pipes[1]); execlp("od", "od", "-c", (char *)0); exit(EXIT_FAILURE); } else { close(1); dub(file_pipes[1]); close(file_pipes[0]); close(file_pipes[1]); execlp("ls","ls","-l",(char *)0); exit(EXIT_FAILURE); } } exit(EXIT_SUCCESS); } printf("Execution finished successfully.... \n\n"); }
ls -l | od -c | wc > out.txt
-> 파이프로 stdin stdout 해서 두 명령어를 리다이렉션해서 out.txt로 넣어야 대는데.
위에 소스는 od -c , ls -l 는 해결되어있습니다.
out.txt로 넣는 과정을 어떻게 해야할까요..ㅠ
Forums:
다양한 방법이 있겠지만, 직접 File을 생성해서
다양한 방법이 있겠지만, 직접 File을 생성해서 파일에 기록하면 될 것 같네요.
댓글 달기