newrw.c
来自「基于网络编程的例子」· C语言 代码 · 共 40 行
C
40 行
/* * piperw.c - The correct way to open a pipe and fork * a child process. */#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <limits.h>#define BUFSZ PIPE_BUFvoid err_quit(char *msg);int main(void){ FILE *fp; /* FILE stream for popen */ char *cmdstring = "cat pipopn.c"; char buf[BUFSZ]; /* Buffer for "input" */ /* Create the pipe */ if((fp = popen(cmdstring, "r")) == NULL) err_quit("popen"); /* "Read" cmdstring's output */ while((fgets(buf, BUFSZ, fp)) != NULL) printf("%s", buf); /* Close and reap the exit status */ pclose(fp); exit(EXIT_SUCCESS);} void err_quit(char *msg){ perror(msg); exit(EXIT_FAILURE);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?