使用 .net 托管代码屏幕抓取命令窗口

发布于 2024-07-05 22:40:59 字数 418 浏览 4 评论 0原文

我正在 dot net 中编写一个程序,它将使用框架 2.0 的 Process 对象执行脚本和命令行程序。 我希望能够访问程序中进程的屏幕缓冲区。 我已经对此进行了调查,看来我需要访问控制台标准输出和标准错误缓冲区。 有人知道这是如何使用托管代码来完成的吗?

我想我需要使用附加到任务的 Windows 控制台的 AttachConsole 和 ReadConsoleOutput 以便从控制台屏幕读取字符和属性数据块。 我需要做的是托管代码。

请参阅 http://msdn.microsoft.com/en-我们/库/ms684965(VS.85).aspx

I am writing a program in dot net that will execute scripts and command line programs using the framework 2.0's Process object. I want to be able to access the screen buffers of the process in my program. I've investigated this and it appears that I need to access console stdout and stderr buffers. Anyone know how this is accomplished using managed code?

I think I need to use the AttachConsole and the ReadConsoleOutput of the windows console attached to the task in order to read a block of character and attribute data from the console screen. I need to do this is managed code.

See http://msdn.microsoft.com/en-us/library/ms684965(VS.85).aspx

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汐鸠 2024-07-12 22:41:00

您可以使用 System.Diagnostics.Process 类的 StandardError、StandardOutput 和 StandardInput 属性来完成此操作。

MSDN 有一个很好的 重定向标准输入和输出的示例< /a> 一个进程。

请注意,您只能重定向您启动的进程的输出。 您未启动的外部进程无法在事后重定向其标准输出。

另请注意,要使用 StandardInput,必须将 ProcessStartInfo.UseShellExecute 设置为 false,并且必须将 ProcessStartInfo.RedirectStandardInput 设置为 true。 否则,写入 StandardInput 流会引发异常。

You can accomplish this using the StandardError, StandardOutput, and StandardInput properties on the System.Diagnostics.Process class.

MSDN has a nice example of redirecting standard in and out of a process.

Note that you can only redirect the output of processes that you started. External processes that you didn't launch can't have their stdout redirected after the fact.

Also note that to use StandardInput, you must set ProcessStartInfo.UseShellExecute to false, and you must set ProcessStartInfo.RedirectStandardInput to true. Otherwise, writing to the StandardInput stream throws an exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文