作者:zieckey (http://zieckey.cublog.cn)
All Rights Reserved!
popen使用FIFO管道执行外部程序。
#include
FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);
popen 通过type是r还是w确定command的输入/输出方向,r和w是相对command的管道而言的。r表示command从管道中读入,w表示 command通过管道输出到它的stdout,popen返回FIFO管道的文件流指针。pclose则用于使用结束后关闭这个指针。
下面看一个例子:
/*******************************************************************************************
** Name:popen.c
** This program is used to show the usage of popen() .
** Author:zieckey,(zieckey@yahoo.com.cn)
** Date:2007/9/30 11:47
** All rights reserved!
*******************************************************************************************/
#include
#include
#include
#include
#include
int main( void )
{
FILE *stream;
FILE *wstream;
char buf[1024];