请问popen函数据第二个参数const char *type设为“w”是什么意思,man写的太简单了不明白?

bekars 2005-02-18 06:03:49
请问popen函数据第二个参数const char *type设为“w”是什么意思,man写的太简单了不明白?
...全文
256 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueflame 2005-02-21
  • 打赏
  • 举报
回复
r:
父进程 子进程
fp <--------- stdout

w:
父进程 子进程
fp ---------> stdin
blueflame 2005-02-21
  • 打赏
  • 举报
回复
popen的作用是创建一个管道并启动一个进程,该进程根据type参数从该管道读出标准输入或是往该管道写入标准输出,如果还是不理解,我记得APUE的进程通信部分是有个popen的实现的,楼主可以好好看看
bekars 2005-02-21
  • 打赏
  • 举报
回复
我想问的是写是往哪里写,在什么情况下用w参数,我一直用r,直接获取命令的输出结果。
reger6410 2005-02-19
  • 打赏
  • 举报
回复
test
tengulre 2005-02-19
  • 打赏
  • 举报
回复
写.
blueflame 2005-02-18
  • 打赏
  • 举报
回复
If mode is r, when the child process is started its file descriptor STDOUT_FILENO will be the writable end of the pipe, and the file descriptor fileno(stream) in the calling process, where stream is the stream pointer returned by popen(), will be the readable end of the pipe.

If mode is w, when the child process is started its file descriptor STDIN_FILENO will be the readable end of the pipe, and the file descriptor fileno(stream) in the calling process, where stream is the stream pointer returned by popen(), will be the writable end of the pipe.
nodummy 2005-02-18
  • 打赏
  • 举报
回复
设置为"w"表示可以写入,"r"表示读取,"r+"表示读写

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧