Results 1 to 3 of 3

Thread: Not All Processes Redirecting Standard Output

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2012
    Location
    Nottingham, UK
    Posts
    44

    Question Not All Processes Redirecting Standard Output

    Hello All, TheMeq here. I have this application that starts a Minecraft Server, and I would like the console text to output to a listbox. It works perfectly fine using the Minecraft Server 1.7.2 jar, but not with the Minecraft Server 1.6.4 jar, or 1.6.2 jar. If I run these commands on the command line, they work as expected, and I've msgbox'd out the full command as it should run, but it doesn't appear to want to work for the 1.6.2 or 1.6.4 jar files.

    Here is my code (additional bits extracted, if required, will post). TabSwitch() is a function that simply switches the current tab in a tabcontrol.
    MS_SERVER_LOCATION and MS_SERVER_JARFILE are all set in another tab when the form loads. As I say, this works perfectly fine for the 1.7.2 jar, just not the 1.6.4 or 1.6.2 jar, although all of them produce console output when run on the command line.

    Minecraft 1.7.2 Server Jar - https://s3.amazonaws.com/Minecraft.D...rver.1.7.2.jar
    Minecraft 1.6.4 Server Jar - https://s3.amazonaws.com/Minecraft.D...rver.1.6.4.jar
    Minecraft 1.6.2 Server Jar - https://s3.amazonaws.com/Minecraft.D...rver.1.6.2.jar

    Code:
    Imports System.IO
    
    Public Class Form1
    
        Public proc As New Process
        Public std_out As StreamReader
        Public std_in As StreamWriter
        Public MS_SERVER_LOCATION As String = ""
        Public MS_SERVER_JARFILE As String = ""
        Public MS_EASTER_EGG As String = ""
        Public ProgramIsRunning As Integer
        Public ServerIsRunning As Integer
        Public ServerIsSet As Integer = 0
    
        Function LogIt(ThisText)
            If ThisText <> Nothing Then
                ListBox1.Items.Add(ThisText)
                ListBox1.SelectedIndex = ListBox1.Items.Count - 1
            End If
            Return 0
        End Function
    
        Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            Dim start_info As New ProcessStartInfo()
    
            start_info.FileName = "java"
            start_info.UseShellExecute = False
            start_info.CreateNoWindow = True
            start_info.RedirectStandardOutput = True
            start_info.RedirectStandardInput = True
            start_info.WindowStyle = ProcessWindowStyle.Hidden
            start_info.Arguments = " -Xmx1024M -Xms1024M -jar " + MS_SERVER_LOCATION + "\" + MS_SERVER_JARFILE + " nogui"
    
            proc.StartInfo = start_info
            proc.Start()
    
            std_out = proc.StandardOutput
            std_in = proc.StandardInput
            Do
                LogIt(std_out.ReadLine)
            Loop While ServerIsRunning = 1
    
        End Sub
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Control.CheckForIllegalCrossThreadCalls = False
            ProgramIsRunning = 1
            If ServerIsSet = 0 Then
                MenuStrip1.Enabled = False
                TabSwitch(7)
            End If
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            ProgramIsRunning = 0
            If ServerIsRunning = 1 Then
                proc.StandardInput.WriteLine("/stop")
                proc.StandardInput.Flush()
                proc.Close()
            End If
        End Sub
    
        Private Sub StartToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles StartToolStripMenuItem.Click
            LogIt("[INFO] Attempting to start server...")
            If MS_SERVER_JARFILE = "" Or MS_SERVER_LOCATION = "" Then
                LogIt("[INFO] Server Jar file and/or Location has not been defined.")
            Else
                LogIt("[INFO] Starting JAVA, Please wait...")
                BackgroundWorker1.RunWorkerAsync()
                ServerIsRunning = 1
                StartToolStripMenuItem.Enabled = False
            End If
    
            TabSwitch(0)
        End Sub
    End Class

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Not All Processes Redirecting Standard Output

    Unfortunately i don't know any thing about minecraft but yet am expected to download external .rar files.

    can you explain this abuse please when your even using the bgw class that handles invoking for you.

    Code:
    Control.CheckForIllegalCrossThreadCalls = False

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2012
    Location
    Nottingham, UK
    Posts
    44

    Re: Not All Processes Redirecting Standard Output

    There jar files actually, linked from minecrafts own website, and I didn't know it was abuse, it was sample code copied from elsewhere.

    Learn to respond a bit nicer. Ta.
    ~ TheMeq ~
    If I helped in anyway, please hit the star and send me some rep! Thanks

Tags for this Thread

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