예전글들

[3] file descriptor redirection using dup2()

진트­ 2008. 4. 17. 23:23

#include <io.h>
#include <stdio.h>
#include <fcntl.h> int main(int argc, char **argv)
{
    int nFD = open("C:\\redirect.txt", O_CREAT|O_RDWR, 0666);

    // 기존 stderr close     close(fileno(stderr));

    // stderr의 출력을 nFD로 redirection
    dup2(nFD, fileno(stderr));
    fprintf(stderr, "this is test\n");
    close(nFD);
    return 0;
}

 

원문

http://blog.daum.net/aswip/2773774

 

이 글은 스프링노트에서 작성되었습니다.