Windows上的unbuffer程序等效于什么? [英] What is the equivalent of unbuffer program on Windows?

查看:175
本文介绍了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 最终支持

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的旧版本上,如果您知道需要多少数据,则原则上可以使用

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程序等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆