Results 1 to 6 of 6

Thread: Java Console??

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Java Console??

    Hello,

    I am working on a admin tools for running game servers.

    This is for servers like Minecraft Bukkit/Spigot/Bungee.

    This is what it looks like.

    Name:  Untitled-1.jpg
Views: 271
Size:  15.6 KB

    Only i was how to run the Java Jar in this program (Inside the big white box)

    Does anyoneknow how to do this?

    Thanks for all the help!


    Greets,
    Djamon Staal

  2. #2
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Java Console??

    It's possible to run applications in an embedded console. I have used http://www.codeproject.com/Articles/...-C-Application and it works well, although I needed to modify it for my own purpose. Unfortunately it's in C# but with some work it could be translated. There may be a VB equivalent out there.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  3. #3
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Java Console??

    Here is the code for my attempt at redirecting standard input/output of "cmd.exe". Just make a new WinForm project and copy the code. Perhaps you can modify it to suit your needs.

    vb.net Code:
    1. Public Class Form1
    2.  
    3.    Private writeCommand As IO.StreamWriter
    4.    Private p As Process
    5.    Private SplitContainer1 As System.Windows.Forms.SplitContainer
    6.    Private tbOutput As System.Windows.Forms.TextBox
    7.    Private tbSendCommand As System.Windows.Forms.TextBox
    8.    Private delAppendOutput As New Action(Of DataReceivedEventArgs)(AddressOf AppendOutput)
    9.  
    10.    Public Sub New()
    11.       InitializeComponent()
    12.       SetUpForm()
    13.    End Sub
    14.  
    15.    Private Sub SetUpForm()
    16.       Me.SplitContainer1 = New System.Windows.Forms.SplitContainer With {.Dock = DockStyle.Fill}
    17.       Me.SplitContainer1.Orientation = Orientation.Horizontal
    18.       Me.SplitContainer1.Panel2MinSize = 0
    19.       Me.SplitContainer1.IsSplitterFixed = True
    20.       Me.tbOutput = New TextBox With {.Dock = DockStyle.Fill, .Parent = Me.SplitContainer1.Panel1, _
    21.                                       .ReadOnly = True, .Multiline = True, .ScrollBars = ScrollBars.Both}
    22.       Me.tbSendCommand = New TextBox With {.Dock = DockStyle.Fill, .Parent = Me.SplitContainer1.Panel2}
    23.       Me.SplitContainer1.Parent = Me
    24.       AddHandler Me.tbSendCommand.KeyPress, AddressOf tbSendCommand_KeyPress
    25.    End Sub
    26.  
    27.    Protected Overrides Sub OnShown(ByVal e As System.EventArgs)
    28.       SetSplitterPosition()
    29.       StartProcess()
    30.       tbSendCommand.Focus()
    31.       MyBase.OnShown(e)
    32.    End Sub
    33.  
    34.    Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
    35.       MyBase.OnClosing(e)
    36.       If Not e.Cancel Then
    37.          CleanUpProcess()
    38.       End If
    39.    End Sub
    40.  
    41.    Private Sub StartProcess()
    42.       Dim si As New Diagnostics.ProcessStartInfo
    43.       With si
    44.          Dim commandToRun As String = "dir"
    45.          .Arguments = "/k " & commandToRun
    46.          .FileName = "cmd.exe"
    47.          .UseShellExecute = False
    48.          .RedirectStandardOutput = True
    49.          .RedirectStandardInput = True
    50.          .CreateNoWindow = True
    51.       End With
    52.  
    53.       p = New Process()
    54.       p.StartInfo = si
    55.       p.EnableRaisingEvents = True
    56.       AddHandler p.OutputDataReceived, AddressOf OutputHandler
    57.       AddHandler p.Exited, AddressOf ProcessExitedHandler
    58.       p.Start()
    59.       p.BeginOutputReadLine()
    60.       writeCommand = p.StandardInput
    61.  
    62.    End Sub
    63.  
    64.    Private Sub OutputHandler(ByVal sendingProcess As Object, ByVal e As DataReceivedEventArgs)
    65.       Me.Invoke(delAppendOutput, New Object() {e})
    66.    End Sub
    67.  
    68.    Private Sub AppendOutput(ByVal e As DataReceivedEventArgs)
    69.       If Not String.IsNullOrEmpty(e.Data) Then tbOutput.AppendText(e.Data & System.Environment.NewLine)
    70.    End Sub
    71.  
    72.    Private Sub ProcessExitedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    73.       CleanUpProcess()
    74.    End Sub
    75.  
    76.    Private Sub CleanUpProcess()
    77.       If p IsNot Nothing Then
    78.          RemoveHandler p.Exited, AddressOf ProcessExitedHandler
    79.          RemoveHandler p.OutputDataReceived, AddressOf OutputHandler
    80.          If Not p.HasExited Then p.Kill()
    81.          p.Dispose()
    82.          p = Nothing
    83.       End If
    84.    End Sub
    85.  
    86.    Private Sub tbSendCommand_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
    87.       Const EnterKey As Char = ChrW(Keys.Enter)
    88.       If e.KeyChar = EnterKey Then
    89.          e.Handled = True
    90.          Dim cmd As String = tbSendCommand.Text.Trim
    91.          If Not String.IsNullOrEmpty(cmd) Then
    92.             writeCommand.WriteLine(cmd)
    93.             tbSendCommand.Clear()
    94.          End If
    95.       End If
    96.    End Sub
    97.  
    98.    Private Sub SplitContainer1_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
    99.       SetSplitterPosition()
    100.    End Sub
    101.  
    102.    Private Sub SetSplitterPosition()
    103.       With SplitContainer1
    104.          .SplitterDistance = .ClientSize.Height - tbSendCommand.Height - .SplitterWidth
    105.       End With
    106.    End Sub
    107. End Class

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: Java Console??

    Thanks for your comment!

    It does almost what i want.
    do you have a script that does:

    @echo off
    java -jar Jar\[FILENAME].jar
    PAUSE

    It also needs to react when i press the start button it needs to start.
    when i press the stop button it needs to enter the commend stop or end in the text line.

    and it it posible to enter the text inside a textbox?


    Greets,
    Djamon Staal

    ______________________________

    Quote Originally Posted by TnTinMN View Post
    Here is the code for my attempt at redirecting standard input/output of "cmd.exe". Just make a new WinForm project and copy the code. Perhaps you can modify it to suit your needs.

    vb.net Code:
    1. Public Class Form1
    2.  
    3.    Private writeCommand As IO.StreamWriter
    4.    Private p As Process
    5.    Private SplitContainer1 As System.Windows.Forms.SplitContainer
    6.    Private tbOutput As System.Windows.Forms.TextBox
    7.    Private tbSendCommand As System.Windows.Forms.TextBox
    8.    Private delAppendOutput As New Action(Of DataReceivedEventArgs)(AddressOf AppendOutput)
    9.  
    10.    Public Sub New()
    11.       InitializeComponent()
    12.       SetUpForm()
    13.    End Sub
    14.  
    15.    Private Sub SetUpForm()
    16.       Me.SplitContainer1 = New System.Windows.Forms.SplitContainer With {.Dock = DockStyle.Fill}
    17.       Me.SplitContainer1.Orientation = Orientation.Horizontal
    18.       Me.SplitContainer1.Panel2MinSize = 0
    19.       Me.SplitContainer1.IsSplitterFixed = True
    20.       Me.tbOutput = New TextBox With {.Dock = DockStyle.Fill, .Parent = Me.SplitContainer1.Panel1, _
    21.                                       .ReadOnly = True, .Multiline = True, .ScrollBars = ScrollBars.Both}
    22.       Me.tbSendCommand = New TextBox With {.Dock = DockStyle.Fill, .Parent = Me.SplitContainer1.Panel2}
    23.       Me.SplitContainer1.Parent = Me
    24.       AddHandler Me.tbSendCommand.KeyPress, AddressOf tbSendCommand_KeyPress
    25.    End Sub
    26.  
    27.    Protected Overrides Sub OnShown(ByVal e As System.EventArgs)
    28.       SetSplitterPosition()
    29.       StartProcess()
    30.       tbSendCommand.Focus()
    31.       MyBase.OnShown(e)
    32.    End Sub
    33.  
    34.    Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
    35.       MyBase.OnClosing(e)
    36.       If Not e.Cancel Then
    37.          CleanUpProcess()
    38.       End If
    39.    End Sub
    40.  
    41.    Private Sub StartProcess()
    42.       Dim si As New Diagnostics.ProcessStartInfo
    43.       With si
    44.          Dim commandToRun As String = "dir"
    45.          .Arguments = "/k " & commandToRun
    46.          .FileName = "cmd.exe"
    47.          .UseShellExecute = False
    48.          .RedirectStandardOutput = True
    49.          .RedirectStandardInput = True
    50.          .CreateNoWindow = True
    51.       End With
    52.  
    53.       p = New Process()
    54.       p.StartInfo = si
    55.       p.EnableRaisingEvents = True
    56.       AddHandler p.OutputDataReceived, AddressOf OutputHandler
    57.       AddHandler p.Exited, AddressOf ProcessExitedHandler
    58.       p.Start()
    59.       p.BeginOutputReadLine()
    60.       writeCommand = p.StandardInput
    61.  
    62.    End Sub
    63.  
    64.    Private Sub OutputHandler(ByVal sendingProcess As Object, ByVal e As DataReceivedEventArgs)
    65.       Me.Invoke(delAppendOutput, New Object() {e})
    66.    End Sub
    67.  
    68.    Private Sub AppendOutput(ByVal e As DataReceivedEventArgs)
    69.       If Not String.IsNullOrEmpty(e.Data) Then tbOutput.AppendText(e.Data & System.Environment.NewLine)
    70.    End Sub
    71.  
    72.    Private Sub ProcessExitedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    73.       CleanUpProcess()
    74.    End Sub
    75.  
    76.    Private Sub CleanUpProcess()
    77.       If p IsNot Nothing Then
    78.          RemoveHandler p.Exited, AddressOf ProcessExitedHandler
    79.          RemoveHandler p.OutputDataReceived, AddressOf OutputHandler
    80.          If Not p.HasExited Then p.Kill()
    81.          p.Dispose()
    82.          p = Nothing
    83.       End If
    84.    End Sub
    85.  
    86.    Private Sub tbSendCommand_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
    87.       Const EnterKey As Char = ChrW(Keys.Enter)
    88.       If e.KeyChar = EnterKey Then
    89.          e.Handled = True
    90.          Dim cmd As String = tbSendCommand.Text.Trim
    91.          If Not String.IsNullOrEmpty(cmd) Then
    92.             writeCommand.WriteLine(cmd)
    93.             tbSendCommand.Clear()
    94.          End If
    95.       End If
    96.    End Sub
    97.  
    98.    Private Sub SplitContainer1_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
    99.       SetSplitterPosition()
    100.    End Sub
    101.  
    102.    Private Sub SetSplitterPosition()
    103.       With SplitContainer1
    104.          .SplitterDistance = .ClientSize.Height - tbSendCommand.Height - .SplitterWidth
    105.       End With
    106.    End Sub
    107. End Class

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: Java Console??

    Hello,

    Let me explain the functionality.

    Name:  Untitled-1 With Box.jpg
Views: 32
Size:  17.4 KB

    When i press "Start" -> The Connected .bat file or .jar file runs as a console in "TextBox1"
    When i press "Stop" -> The form enters "stop" in "TextBox2" and automaticly sends it to the console.
    When i press "Reload" -> The form enters "reload" in "TextBox2" and automaticly sends it to the console.
    When i press "Clear Console" -> "TextBox1" needs to be clean buth the server needs to be online.


    The server needs to be inside "TextBox1" and needs to show the same information as when you are just starting a minecraft server like this:

    Name:  MineCraft Server.jpg
Views: 36
Size:  37.0 KB

    No,
    i am not working with this kind of server.
    I am running a Spigot server.

    you can get it from: http://getspigot.org/

    make a start.bat file with this inside
    Code:
    @echo off
    java -jar Jar\spigot_server.jar
    PAUSE
    Put the 2 files in the same folder. (It will generate files!)
    and start de "Start.bat" file


    This is the kind of stuff i mean, this needs to be inside "TextBox1"

    Name:  Spigot Console CMD.jpg
Views: 34
Size:  57.0 KB



    Greets,
    Djamon Staal
    Attached Images Attached Images   

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Java Console??

    I don't know if programs that you wish to run will work well with IO redirection. You will need to test them to see if this technique works or not.

    Quote Originally Posted by sjamondaal View Post
    do you have a script that does:

    @echo off
    java -jar Jar\[FILENAME].jar
    PAUSE
    I am not sure about what you mean by "do you have a script", but commands are sent to the command window using the StreamWriter object named writeCommand. So you could send those commands like this:
    Code:
    writeCommand.WriteLine("echo off")
    writeCommand.WriteLine("java -jar Jar\[FILENAME].jar")
    Quote Originally Posted by sjamondaal View Post
    It also needs to react when i press the start button it needs to start.
    when i press the stop button it needs to enter the commend stop or end in the text line.

    and it it posible to enter the text inside a textbox?
    The code as provided place a TextBox positioned at the bottom of the form that you can type commands into. The text is sent to the command window when you press enter. As far as what your buttons do or don't do, that is up to how you code the Click handler for them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width