popendemo.c
来自「unix linux 编程实践源代码」· C语言 代码 · 共 26 行
C
26 行
/* popendemo.c * demonstrates how to open a program for standard i/o * important points: * 1. popen() returns a FILE *, just like fopen() * 2. the FILE * it returns can be read/written * with all the standard functions * 3. you need to use pclose() when done */#include <stdio.h>#include <stdlib.h>int main(){ FILE *fp; char buf[100]; int i = 0; fp = popen( "who|sort", "r" ); /* open the command */ while ( fgets( buf, 100, fp ) != NULL ) /* read from command */ printf("%3d %s", i++, buf ); /* print data */ pclose( fp ); /* IMPORTANT! */ return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?