4:
5: #dene MAX_LINE 80
6: #dene PIPE_STDIN 0
7: #dene PIPE_STDOUT 1
8:
9: int main()
10: ...{
11: const char *string=...{"A sample message."};
12: int ret, myPipe[2];
13: char bu?er[MAX_LINE+1];
14:
15: /**//* 建立管道@*/
16: ret = pipe( myPipe );
17:
18: if (ret == 0) ...{
19:
20: /**//* 将消息写入管道@*/
21: write( myPipe[PIPE_STDOUT], string, strlen(string) );
22:
23: /**//* 从管道读取消息@*/
24: ret = read( myPipe[PIPE_STDIN], bu?er, MAX_LINE );
25:
26: /**//* 利用 Null 结束字符串@*/
27: bu?er[ ret ] = 0;
28:
29: printf("%s\n", bu?er);
30:
31: }
32: