本文介绍了Java控制台应用程序到VB.net中的RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有人说'Google it'之前,我已经用Google搜索了这个。我尝试的一切都行不通。唯一一个DID工作,忽略JAVA执行并专注于命令提示符,所以它给了我[java -jar C:\ FileDir \ file.jar nogui]并停止,当我通过命令提示符终止它时,它显示'暂停'命令。 JAVA没有显示任何内容,但我知道.jar提供了一些信息,因为它创建的文件确实已经制作完毕。





好了,现在已经结束了,我想在程序执行时追加控制台。它是一个实时函数,在提供暂停命令之前不会终止。我有halt命令和一切就绪,但它没有显示RichTextBox中的控制台,因为我需要它。我试图在代码之后改变代码并确实自己创建,但无济于事。控制台本身显示恒定的文本行,(例如'[CORE] Setup is initilizing'或'[CRITICAL] File'axmla.xaml'找不到')但我需要做的是在制作这些行时附加这些行并将它们输入RTB。







这是我到目前为止所拥有的...

Before anyone says 'Google it', I HAVE Googled this. Everything I try doesn't work. The only one that DID work, ignored the JAVA execution and focused on the command prompt, so it gave me [java -jar C:\FileDir\file.jar nogui] and stopped, when I terminated it via Command Prompt, it showed the 'pause' command. Nothing from JAVA showed, but I do know that the .jar provided some information, as the files that it would create were indeed made.


Ok, now that that is over, I am tying to Append the console when the program is executed. It is a live function and does not terminate until a halt command is provided. I have the halt command and everything in place, however it does not show the console in the RichTextBox as I need it to. I have tried to alter code after code and indeed make my own, but to no avail. The console itself shows constant lines of text, (such as '[CORE] Setup is initilizing' or '[CRITICAL] File 'axmla.xaml' cannot be found') but what I need to do is append those lines as they are made and input them to the RTB.



This is what I have so far...

'This is in a button control ##
   _commandExecutor.Execute("java.exe", " -jar file.jar")
'End Button Control ##

'Start Console Read/Execute ##
Public Class CommandExecutor
    Implements IDisposable

    Public Event OutputRead(ByVal output As String)

    Private WithEvents _process As Process

    Public Sub Execute(ByVal filePath As String, ByVal arguments As String)
        If _process IsNot Nothing Then
            Throw New Exception("The service is already started.")
        End If
        _process = New Process()
        _process.StartInfo.FileName = filePath
        _process.StartInfo.Arguments = arguments
        _process.StartInfo.UseShellExecute = False
        _process.StartInfo.RedirectStandardInput = True
        _process.StartInfo.RedirectStandardOutput = True
        '_process.StartInfo.CreateNoWindow = True  ------ ## Reenable when working ## ------
        _process.Start()
        _process.BeginOutputReadLine()
    End Sub

    Private Sub _process_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles _process.OutputDataReceived
        If _process.HasExited Then
            _process.Dispose()
            _process = Nothing
        End If
        RaiseEvent OutputRead(e.Data)
    End Sub

    Private disposedValue As Boolean = False
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                If _process IsNot Nothing Then
                    _process.Kill()
                    _process.Dispose()
                    _process = Nothing
                End If
            End If
        End If
        Me.disposedValue = True
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
' ## End Console Read/Execute







我希望有人能理解。如果你需要进一步澄清,

推荐答案


这篇关于Java控制台应用程序到VB.net中的RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:03