Results 1 to 14 of 14

Thread: Getting feed from minecraft_sever.jar

  1. #1
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0

    Getting feed from minecraft_sever.jar

    Hey guys,

    I'm currently trying to receive a feed from the java app minecraft_sever.jar.
    This is what I am currently doing:

    Code:
        Dim mc_server As New Process    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            mc_server.StartInfo.UseShellExecute = False
            mc_server.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
            mc_server.StartInfo.RedirectStandardOutput = True
            mc_server.StartInfo.RedirectStandardInput = True
            mc_server.StartInfo.CreateNoWindow = True
            mc_server.StartInfo.FileName = "C:\Program Files (x86)\Java\jre6\bin\java.exe"
            mc_server.StartInfo.Arguments = "java -Xmx1024M -Xms1024M -jar C:\Other\Minecraft\minecraft_server.jar nogui"
            mc_server.Start()
            While (mc_server.HasExited = False)
                Dim sLine As String = mc_server.StandardOutput.ReadLine
                If (Not String.IsNullOrEmpty(sLine)) Then
                    ListBox1.Items.Add(sLine)
    
    
                End If
                Application.DoEvents()
            End While
        End Sub
    Sadly, it's not working, and I have no clue why. Could anybody please help me?

    Thanks!
    -Epic

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    Arguments = "java -Xmx1024M ...
    I don't think "java" is a valid argument to be passed to the java.exe process.

    Also, you should not run that loop in UI thread, instead you should get rid of the loop and use the OutputDataReceived event, see Process.OutputDataReceived Event (System.Diagnostics)

  3. #3
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    And how should I change the code with the Process.OutputDataReceieved Event?

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    Add event handler (see code example), call BeginOutputReadLine to start receiving. Also you should set SynchronizingObject property.

    Actually you can set up most of this object in designer by adding it to form from Toolbox, and configure properties and events as any other component. Doing that would also automatically set SynchronizingObject property for you.

  5. #5
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    I understand what you are saying and what I am supposed to do, but I just can't seem to figure it out. Could you help me?

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    Start with finding the Process component in Toolbox and add it to your form.
    Use Properties window to configure all properties, also set EnableRaisingEvents property. In same window switch to Events and doubleclick the OutputDataReceived event.
    The only code you need to write is to start the process and start reading output, for example:
    Me.JavaProcess.Start()
    Me.JavaProcess.BeginOutputReadLine()

    and code to get output data in your OutputDataReceived event handler, for example:
    If e.Data = String.Empty Then Return
    Me.JavaListBox.Items.Add(e.Data)

  7. #7
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    Thank you so much! I finally got it, added the process and everything and did everything correctly... but now there is another weird thing. Everytime I start it from my application it does everything like it's supposed to, but all it does is printing these lines:

    182 Recipes
    27 Achievements
    Those are the two lines the Minecraft Sevrer always outputs, but then it continues and in my application it stopped. I started the server from cmd also too, with this line:
    java.exe C:\Minecraft\minecraft_server.jar nogui And it printed everything correctly and the server started. Now what I don't know is why in my application it's not outputting the rest?

    Now I have also noticed another weird thing, in the Debug Folder are now all the server.properties, the world files and everything but it should actually be in C:\Other\Minecraft\minecraft_server.jar, right? Because that's the argument I have in my process.
    Last edited by Epic; 05-19-2012 at 3:47 PM.

  8. #8
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    it should actually be in C:\Other\Minecraft\minecraft_server.jar, right? Because that's the argument I have in my process.
    You have to set WorkingDirectory property if you want that to be the process working directory.

    I deleted your attachment because (a) it was an invalid zip file, and (b) the rar file only contained binaries.

  9. #9
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    Ops, sorry about that. And yes, I already set the WorkingDirectory.

    Reuploaded the file. Still not working tough, even with the WorkinDirectory. Only output I get is the 2 lines.

  10. #10
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    I deleted your attachment because it contained binary files. You can upload project source files only (without the Bin and Obj folders), if you find it necessary to provide more than you could post in a code box or a few here.

  11. #11
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    Only output I get is the 2 lines.
    The other lines are outputted to StandardError. You can redirect that as well and set up the event handler for ErrorDataReceived event just like the OutputDataReceived event. Actually, if you don't care where the output comes from you can use the same event handler for both, just add to the handles list or in properties window select the same event handler for ErrorDataReceived also.

  12. #12
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    Hey,

    thank you so much. Now, I added the EventHandler for ErrorOutput to my OutputDataReceived, which looks like this:
    Private Sub JavaProcess_OutputDataReceived(ByVal sender As System.Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles JavaProcess.OutputDataReceived, JavaProcess.ErrorDataReceived If e.Data = String.Empty Then Return
    Me.JavaListBox.Items.Add(e.Data)
    End Sub
    And also set the Property for "ErrorDataReceviedOutput" to true now too. But now nothing is being printed in my ListBox. Weird.

  13. #13
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    To begin reading error output you have to call BeginErrorReadLine, just like the corresponding BeginOutputReadLine for StandardOutput. Don't be afraid to read the relevant documentation when you're in pursuit of using a class.

  14. #14
    Epic is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    8
    Reputation
    0
    John, thank you so much for your help. I really appreciate it. It finally worked!

    Quick question: When I know stop the server using the in-server command "/stop" and in VB "JavaProcess.kill", the process (in TaskManager) is killed. but now when I try to restart (like click on "Restart") I get this:

    An async read operation has already been started on the stream.


    So how can I restart the async operation?
    Last edited by Epic; 05-20-2012 at 9:31 PM.

Bookmarks

Posting Permissions

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