美文网首页
[Linux进程间通信]popen和pclose函数

[Linux进程间通信]popen和pclose函数

作者: longtzw | 来源:发表于2013-09-21 10:35 被阅读0次

使用

FILE *popen(const char *cmdstring, const char *)
成功返回文件指针,出错返回NULL
    
int pclose(FILE *fp)
cmdstring的终止状态,如出错则返回-1

函数popen先执行fork,然后调用exec以执行cmdstring,并返回一个标准I/O
文件指针

  • 若type是"r",则文件指针连接到cmdstring的标准输出
  • 若type是"w",则文件指针连接到cmdstring的标准输入

pclose函数关闭标准I/O流,等待cmdstring执行结束,并返回终止状态

相关文章

网友评论

      本文标题:[Linux进程间通信]popen和pclose函数

      本文链接:https://www.haomeiwen.com/subject/xhfqtttx.html