Windows上的unbuffer程序等效于什么?

编程入门 行业动态 更新时间:2024-10-22 15:40:36
本文介绍了Windows上的unbuffer程序等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,根据此帖子,unbuffer通过伪终端(pty)连接到命令,使系统将其视为交互过程,因此不使用任何stdout缓冲.

Hi according to this post, unbuffer connects to a command via a pseudo-terminal (pty), which makes the system treat it as an interactive process, therefore not using any stdout buffering.

我想在Windows上使用此功能.我可以知道Windows上unbuffer程序的等效功能吗?谢谢.

I would like to use this function on Windows. May I know what is the equivalent of unbuffer program on Windows? Thanks.

推荐答案

您所描述的行为是使用运行时库进行I/O的应用程序的典型行为.默认情况下,大多数运行时库都会检查该句柄是否是字符模式设备(例如控制台),如果是,则它们不进行任何缓冲. (理想情况下,运行时库将以与控制台相同的方式处理管道,但似乎大多数情况下没有.)

The behaviour you're describing is typical of applications using run-time libraries for I/O. By default, most runtime libraries check to see whether the handle is a character mode device such as a console, and if so, they don't do any buffering. (Ideally the run-time library would treat a pipe in the same way as a console, but it seems that most don't.)

我不知道有任何明智的方法来欺骗此类应用程序,使其认为它实际上是在向管道中写入控制台.

附录::七年后,Windows 最终支持伪控制台.如果您在Windows 10 v1809或更高版本上运行,则此新API应该可以解决您的问题.

Addendum: seven years later, Windows finally supports pseudoconsoles. If you are running on Windows 10 v1809 or later, this new API should solve your problem.

在Windows的旧版本上,如果您知道需要多少数据,则原则上可以使用控制台API函数为应用程序创建要写入的控制台,然后从该控制台读取输出.但是您不能使用Java来做到这一点,您需要编写一个C应用程序来为您完成这项工作.

On older versions of Windows, if you know how much data to expect, you could in principle use the console API functions to create a console for the application to write to, and then read the output from the console. But you can't do that from Java, you would need to write a C application to do it for you.

类似地,原则上,应该应该可以写出与Unix伪终端等效的设备驱动程序,该伪驱动程序的行为类似于管道,但报告自己为字符模式设备.但是编写设备驱动程序需要特定的专业知识,并且必须进行数字签名,因此,除非那里没有现有产品,否则这种方法不太可行.

Similarly, in principle it should presumably be possible to write a device driver equivalent to a Unix pseudo-terminal, one that acts like a pipe but reports itself to be a character-mode device. But writing device drivers requires specific expertise, and they have to be digitally signed, so unless there is an existing product out there this approach isn't likely to be feasible.

更多推荐

Windows上的unbuffer程序等效于什么?

本文发布于:2023-11-17 07:02:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   Windows   unbuffer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!