如何使我的仅阅读流媒体流非缓冲?

发布于 2025-01-29 18:41:48 字数 415 浏览 2 评论 0原文

据我所知,调用shell命令和读取其输出的建议方法是通过popen(例如,这个答案)。但是,popen(3)的人页面说:

Note that output popen() streams are block buffered by default.

如何使我的只读管道非缓冲?

例如:

FILE* ro_pipe = popen("echo hello", "r");

不会填写4KB输出缓冲区,但是我想在将其写入Shell命令的Stdout后立即准备好读取。

As far as I can tell, the advised method of calling a shell command and reading its output is via popen (e.g., this answer). However, the man page for popen(3) says:

Note that output popen() streams are block buffered by default.

How do I make my read-only pipe non-buffered?

For example:

FILE* ro_pipe = popen("echo hello", "r");

won't fill out the 4KB output buffer, but I'd want to have the output data ready to read as soon as it is written to the stdout of the shell command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文