输出不可重定向的实用程序(Windows) [英] Utility with unredirectable output (Windows)

查看:213
本文介绍了输出不可重定向的实用程序(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft命令行实用程序执行任务.我认为,实用程序的功能及其执行的任务的具体细节相对而言并不重要.这是重要的:

I am using a Microsoft command-line utility to perform a task. The specific details of what the utility does and the task it performs are, I think, relatively unimportant. This is what is important:

命令行实用程序将文本发送到控制台窗口.尽管我尝试了所有可以通过研究找到的方法,但是我无法弄清楚如何将文本重定向到文件.似乎该实用程序正在使用一些奇怪的OS函数调用,从而导致以不受常规重定向方式约束的方式来打印文本.我正在使用Windows 7 cmd.exe控制台窗口.

The command-line utility emits text to the console window. I cannot figure out how to redirect this text to a file, though I have tried every approach I could find through research. It seems the utility is using some strange OS function call that causes text to be printed in a way that is not subject to the normal means of redirection. I am using a Windows 7 cmd.exe console window.

以下任何一种构造都不会重定向有问题的文本输出:

None of these constructs redirect the text output in question:

util.exe >log.txt
util.exe 2>err.txt
util.exe >log.txt 2>&1
util.exe 1>log.txt 2>err.txt
util.exe 1>log.txt 2>err.txt 3>3.txt 4>4.txt 5>5.txt 6>6.txt 7>7.txt 8>8.txt 9>9.txt

对最后一个感到困惑吗?

Confused about that last one? Turns out there are 10 output streams in Windows-land, but that didn't get the job done either.

我可以使用控制台窗口的编辑">标记选择并复制"功能来复制文本,但是我需要以无头方式捕获该程序的输出,以便使其自动化.

I can copy the text using the console window's Edit>Mark select-and-copy functionality, but I need to capture this program's output in a headless way so that it can be automated.

我找不到绕过重定向直接打印到控制台的任何OS函数调用.是否存在这样的功能?该实用程序如何设法规避重定向?而我可以使用什么方式来捕获该实用程序的输出呢?

I cannot find any OS function call that specifically prints to the console bypassing redirection. Does such a function exist? How does this utility manage to circumvent redirection? And what means could I use to capture this utility's output?

我还尝试了DbgView,认为可能包含输出消息,但没有.

I also tried DbgView, thinking maybe that might contain the output messages, but it did not.

该实用程序不是图形实用程序.很显然,这是一个文本模式程序,可能是用C或C ++编写的.它是由Microsoft编写的.

The utility is not a graphical utility. It is pretty obviously a text-mode program, probably written in C or C++. It was written by Microsoft.

推荐答案

没有什么特别神奇的.尽管C库默认将输出发送到标准输出句柄,但是程序没有义务这样做.您可以始终打开控制台输出设备(CONOUT$)的自己的句柄.

There's nothing particularly magical about it. Although the C library defaults to sending output to the standard output handle, there's no obligation for a program to do so; you can always open your own handle to the console output device (CONOUT$) instead.

请参见 CreateFile 有关控制台设备的更多信息.

See the documentation on CreateFile for more information about console devices.

在捕获输出方面,您可以使用

In terms of capturing the output, you may be able to do something with ReadConsoleOutput and friends, but it isn't straightforward.

这篇关于输出不可重定向的实用程序(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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