Command Line Inside of Windows Form

fizban610

New member
Joined
Aug 14, 2012
Messages
3
Programming Experience
3-5
Ok I have been searching on google for over an hour on how to do this. This is my goal. I play the game minecraft and the server is a java application that runs in the console window. What I would like to do is make a GUI for the server to view the console window in one tab and in the other tabs make quick changes by pressing buttons and what not to send commands to the window. or edit configuration files on the fly. So the main part that I am having trouble is to open my start.bat file which normally would open the cmd.exe and run the server window within it. I want to be able to open that file from my program and have to output displayed in a multi-line text box that can update in real time and be able to send commands at the click of a button.

I hope this made sense and someone can help.

Thanks,
Fiz
 
Add the Process component from toolbox to your form and configure it, especially you need to redirect input/output. Add event handlers for the Output/ErrorDataReceived events and call BeginErrorReadLine/BeginOutputReadLine methods to start listening to those, though start the process with Start method first. Input can be written to StandardInput. Look up the help for Process class and ProcessStartInfo class for relevant info.
 
So my program is starting to work well I have it loading up the program and displaying what is happening in a multiline textbox but cannot send commands to it. here is my code.

VB.NET:
Public Class Form1
    Private Delegate Sub AppendOutputTextDelegate(ByVal text As String)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        psCMD.Start()
        psCMD.BeginErrorReadLine()
        psCMD.BeginOutputReadLine()
        AppendOutputText(vbCrLf & "Bukkit Started at: " & psCMD.StartTime.ToString)
    End Sub


    Private Sub psCMD_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles psCMD.ErrorDataReceived
        AppendOutputText(vbCrLf & e.Data)
    End Sub


    Private Sub psCMD_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles psCMD.OutputDataReceived
        AppendOutputText(vbCrLf & e.Data)
    End Sub
    Private Sub threadtask()


    End Sub


    Private Sub AppendOutputText(ByVal text As String)  'this one was borrowed from another project not sure if i need it.
        If TextBox1.InvokeRequired Then
            Dim myDelegate As New AppendOutputTextDelegate(AddressOf AppendOutputText)
            Me.Invoke(myDelegate, text)
        Else
            'TextBox1.Text = text
            Dim online As String = text
            If text.Contains("[INFO] Connected players:") Then
            Else
                TextBox1.AppendText(text)
            End If
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        psCMD.StandardInput.WriteLine(TextBox2.Text)
    End Sub
End Class

when i type something into textbox2 and click button2 nothing happens. any help on how i can fix this problem would be greatly appreciated.

~Fiz
 
The InvokeRequired/Invoke code is not needed, because SynchronizingObject property has been set.

I don't know your troubles with StandardInput, for example the StreamWriter used is set to AutoFlush by default. It could be that the process has exited at that point - check HasExited property, or you could listen to Exited event and dispose the process and disable input when that happens.
 
Back
Top