Click here to Skip to main content
15,745,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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...
VB
'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



I'm hoping someone will understand. If you need further clarification, DO NOT SAY 'This makes no sense!' or start up with the stupid remarks. Just say 'Explain more please, it's hard to understand what you mean'
Posted
Updated 11-Aug-13 7:32am
v2
Comments
Richard MacCutchan 11-Aug-13 13:33pm    
As someone who only joined today it ill behoves you to give orders in your question.
Member 10202697 11-Aug-13 13:46pm    
Actually I had an old account that I forgot the information to and the e-mail is long gone... I was used to people saying all that stuff when I asked a question before and didn't enjoy the comments that well. I do realize though that I went a little overboard with it.
Sergey Alexandrovich Kryukov 11-Aug-13 14:46pm    
You did not "enjoy the comments"? Too bad. Instead of getting help, you are looking for pleasure, aren't your? How can anyone give you good comments if you persistently give us really strong reasons for negative comments, including two comments you gave us today.

Think about it: you say "help me, but don't add comments I would not like". Isn't it childish and arrogant?
And then you explain that this is because "you did not enjoy" some comments.

It simply means that you should better leave the site, which is probably designed for a bit more mature or reasonable people...

—SA
Member 10202697 11-Aug-13 17:34pm    
No, it just means I have better things to do then read through snide remarks. No I'm not looking for 'pleasure' (Where'd you get that idea), I just don't want to have people posting things such as 'Google it' or others like this one. A bit more mature or reasonable people? Well, that seems appropriate, considering I did not say 'help me, but don't add comments I would not like', I said help me, but don't say 'Google it' or remarks that people begin to think that they are superior to another. Childish and arrogant? No it wasn't. In fact, a mature person would wish to assist me, I asked for help and would like to at least get some, instead of these comments that are pointless and nothing more than a waste of my time, and yours for writing them.
Sergey Alexandrovich Kryukov 11-Aug-13 22:18pm    
Well, well...
—SA

1 solution

It does not look as though you have added a handler for your OutputRead event. See http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^] for a sample of how it should be done.
 
Share this answer
 
Comments
Member 10202697 11-Aug-13 13:47pm    
That is the problem however, when I add a handler for OutputRead, it produces nothing in return.
Sergey Alexandrovich Kryukov 11-Aug-13 14:49pm    
Sorry, where did you add it? It's the '+=' operator or AddHandler. Where is it?
—SA
Member 10202697 11-Aug-13 17:37pm    
Where is it? I removed it! The code itself was causing errors so instead of deal with the confusing error (It didn't even give a proper error), I removed it and attempted to remake it. When that failed, I Googled, and finally lead me to here, where I'd wish to get help from community members, not those who post those snide comments.
Sergey Alexandrovich Kryukov 11-Aug-13 22:17pm    
Okay, to see the effect of some event invocation, you always need to add your handle to the invocation list of the event instance, how else? Do it, and when the event is invoked, the handler will be called...
—SA
Sergey Alexandrovich Kryukov 11-Aug-13 14:47pm    
Agree, 5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900