从stdin 读入 输出到stdout

来源:互联网 发布:为mysql设置密码 编辑:程序博客网 时间:2024/06/05 11:56
#include "apue.h"


#define BUFFSIZE 1024


int main ()
{
        char buf[BUFFSIZE];
        int n;
        while( (n = read(STDIN_FILENO,buf,BUFFSIZE) ) >0 )
        {
                if (write(STDOUT_FILENO,buf,n) != n)
                        err_sys("write error");
        }


        if(n < 0)
                err_sys("read error");


        exit(0);

}



运行结果:

<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:./1_2
hello
hello
word
word
world
world
^C<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:./1_2
hello
hello
world
world








eof
eof
EOF
EOF
^Z[1] + Stopped (SIGTSTP)        ./1_2
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:./1_2
HELLO
HELLO
WORLD
WORLD
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:                 ^[
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:ps -ef | grep 1_2
tingbinz 18890  8507  0 02:31:54 pts/285  0:00 ./1_2
tingbinz 24402  8507  0 02:32:59 pts/285  0:00 grep 1_2
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:fg 1_2
ksh: 1_2: Arguments must be %job or process ids
<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:fg 18890
./1_2
hello
hello
^C<bldc:/home/tingbinz/apue.2e/include/1>R*_*G:


0 0
原创粉丝点击