您好,根据此帖子,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程序等效于什么?
发布评论