如何读取控制台缓冲区VBNET? [英] How to read Console buffer in VBNET?

查看:153
本文介绍了如何读取控制台缓冲区VBNET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了使用ConsoleRead API函数C#示例,但是当我试图把它翻译为VBNET我收到了很多的错误,也是在其他网站类似的PInvoke独特的例子是C#也一样,我不能(如果存在的方式来阅读,而不APIS然后我得到不知道控制台缓冲区中)找到任何良好的信息为ConsoleRead API函数VBNET。

I've seen a C# example using ConsoleRead API function but when I've tried to translate it to VBNET I get a lots of errors, also in other sites like pinvoke the unique example is for C# too, I can't find any good information for VBNET of ConsoleRead API function (if exist a way to read the console buffer without APIS then I get no idea).

另外,我已经试过这个控制台缓冲区读写班VBNET( http://pastebin.com/XYxakDTV ),但它抛出一个未处理的异常与这样的控制器无效。

Also I've tried this console buffer reader Class for VBNET (http://pastebin.com/XYxakDTV) but it throws an unhandled exception with message like this "Controller not valid".

有人能说明我和所有其他人对如何从一个GUI应用程序(WindowsForm)启动一个进程VBNET一个例子来读取控制台输出检索字符/字符串?

Someone could illustrate me and all other people with an example for VBNET of how to launch a process from a GUI app (WindowsForm) to read the console output to retrieve characters/strings?

更新:

我不知道,但我认为一个启动的过程(使用System.Process类)没有控制台分配给应用程序,所以我觉得这一切都在这里看到MSDN中的例子不能帮助我的 http://msdn.microsoft.com/en-us/library/system.console.aspx

I'm not sure but I think that a launched process (using System.Process Class) does not assign the console to the app so I think that all the examples seen here in MSDN could not help me: http://msdn.microsoft.com/en-us/library/system.console.aspx

推荐答案

使用

StandardOutput.Read

我认为答案是相同的其他问题运行一个命令行程序,并得到输出,而这一进程仍在运行?

编辑你所要求的一个窗体应用程序读取控制台输出。因此,让我们有一个控制台应用程序():

Edit you are asking for an form application to read console output. So let's have a console application ():

Module Module1

    Sub Main()
        While True
            ' data = Console.ReadKey.KeyChar
            Dim Generator As System.Random = New System.Random()
            Console.Write(Generator.Next(0, 100) & " ")
            Threading.Thread.Sleep(1000)
        End While
    End Sub

End Module 

它每秒产生一个空间分隔的数字之一。 现在,表单应用程序。让我们形成具有多行文本框 txtResult 按钮 cmdStart

It generates a space separated numbers one per second. Now the forms application. Let's have a form with a multiline TextBox named txtResult and a button cmdStart :

Private Sub cmdStart_Click(sender As Object, e As EventArgs) Handles cmdStart.Click
        Dim ProcInfo As New ProcessStartInfo With
            {.FileName = "DataApp.exe", .RedirectStandardOutput = True, .UseShellExecute = False}
        Dim proc As Process = Process.Start(ProcInfo)

        While Not proc.HasExited
            Dim a As String = ChrW(proc.StandardOutput.Read)
            If a = " " Then
                txtResult.Text &= vbCrLf
            Else
                txtResult.Text &= a
            End If
            Threading.Thread.Sleep(100)
            Application.DoEvents()
        End While

    End Sub

它写的数字,每行的文本框之一。没有API神奇,但它的工作原理。

It writes the numbers to the TextBox one per a line. There is no API magic but it works.

这篇关于如何读取控制台缓冲区VBNET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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