프로그램에 두 줄의 함수 호출만 추가하여
std i/o를  redirection하는 함수를 만들려다..
결국 만들었습니다!!
아..재밌는데 더 하긴 귀찮네요.

// redirection_in.cc
// redirection in을 간단히 사용하기 위한 함수를 정의
// 키보드 입력을 파일로 대체!

#include <fcntl.h>
#include <sys/io.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <sys/wait.h>

int redirect_original_stdin;

int redirect_stdin_to_file( char * fname )
{
    // stdin을 keyboard에서 read pipe로 대체하는 함수
   
    // 1. pipe 초기화
    // 2. fork로 자식 프로세스 생성
    //    부모 - stdin(키보드)을 복제, stdin을 read pipe로 대체, read pipe 닫기, 0을 리턴
    // 여기서부턴 자식 프로세스만
    // 3. 파일 오픈
    // 4. 파일 내용을 write pipe에 기록
    // 5. 파일 닫고
    // 6. write pipe 닫고
    // 7. 종료(return 말고 exit)
   
    int pid, result;
    int redirect_fdpipe[2];
   
    if( pipe(redirect_fdpipe) == -1 )
        return 0;
       
    pid = fork();
    if( pid>0 )
    {
        close( redirect_fdpipe[1] );
        redirect_original_stdin = dup( STDIN_FILENO );
        dup2( redirect_fdpipe[0], STDIN_FILENO );
        close( redirect_fdpipe[0] );

        return 0;
    }
    else if( pid==0 )
    {
        // 이 자식 프로세스가 입력 파일을 읽어서
        // 부모 프로세스의 stdin에게 전달한다.
       
        int n,i;
        const int BUFFSIZE = 100;
        char buf[BUFFSIZE];
       
        close( redirect_fdpipe[0] );
       
        FILE * file;   

        file = fopen( fname, "r" );
        if( file==NULL )
            exit(0);
       
        i = 0;
        while( (n=fread(buf,1,BUFFSIZE,file))>=0 )
        {
            if( n>0 )
            {
                write( redirect_fdpipe[1], buf, n );
                i = 0;
            }
            else
            {
                if( ++i>10 )
                    break;
            }
        }
       
        close( redirect_fdpipe[1] );
        exit(0);
    }
}

int redirect_stdin_restore()
{
    // stdin을 read pipe에서 keybooard로 복구하는 함수
   
    // 1. 버퍼에 있는 데이터들 전부 처리(fflush)
    // 2. stdin (파이프) 닫기
    // 3. 백업한 stdin의 descriptor을 이용해 stdin을 키보드로 복구(dup2)
   
    int result;
   
    fflush( stdin );    // 이거없음 곤란한 경우 가끔 발생
       
    result = close( STDIN_FILENO );
    if( result<0 )
        return -1;

    result = dup2( redirect_original_stdin, STDIN_FILENO );   
    if( result<0 )
        return -1;
       
    return 0;
}

int main(int argc, char **argv)
{
    int result;
   
    // 예제 1
    // file을 stdin 입력으로-
    result = redirect_stdin_to_file( "input.dat" );
    if( result<0 )
    {
        printf("redirect_stdin_to_file error\n");
        return 0;
    }
   
    // 아래 fork는 redirection이 아니라 서브 프로그램을 실행하기 위한 절차
    int pid = fork();
    if( pid==0 )
    {
        execl( "./sinout", "/sinout", NULL );
        exit(0);
    }
    else if( pid>0 )
    {
        int status;
        wait( &status );
    }
    else
    {
        // error!
    }
   
    result = redirect_stdin_restore();
    if( result<0 )
    {
        printf("redirect_stdin_restore error\n");
        return 0;
    }
   
    return 0;
}

Posted by 배트
,