I created a Process that is targeted to the Java.exe file. The process should run a Java.jar server file, and continue to run giving output feedback until the server crashed or I forcefully close it down. Everything works fine.. the server is running.. and when I set UseShellExecute to True I can see the black CMD window returning all the output. But when I set it to false and redirect the output... the Window is completely blank ( the server is still running though ) and the OutputDataReceived event doesn't fire at all ( I think I got it to once but that was when I closed the window it seemed the args was empty ) and as far as I can see StandardOutput.ReadToEnd() isnt returning anything either. Why is this Process not returning any Output feedback?? Here is my code:
gameServerProcess = new Process();
gameServerProcess.StartInfo.UseShellExecute = false;
gameServerProcess.StartInfo.RedirectStandardOutput = true;
gameServerProcess.StartInfo.RedirectStandardInput = true;
gameServerProcess.EnableRaisingEvents = true;
gameServerProcess.Exited += new EventHandler(gameServer_WindowExit);
window = new ServerWindow();
gameServerProcess.OutputDataReceived += new DataReceivedEventHandler(window.server_recievedOutputStream);
window.Show();
gameServerProcess.StartInfo.FileName = @"D:\Program Files\Java\jdk1.6.0_12\bin\java.exe";
gameServerProcess.StartInfo.WorkingDirectory = @"D:\Users\Zack\Desktop\ServerFiles\gameserver";
gameServerProcess.StartInfo.Arguments = @"-Xmx1024m -cp ./../libs/*;l2jserver.jar net.sf.l2j.gameserver.GameServer";
gameServerProcess.Start();
gameServerProcess.BeginOutputReadLine();
And my 'window' form class code which should receive the DataReceivedEventArgs with the output data:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace MWRemoteServer
{
public partial class ServerWindow : Form
{
private delegate void WriteOutputDelegate(string output);
private WriteOutputDelegate writeOutput;
public ServerWindow()
{
InitializeComponent();
logBox.BackColor = Color.White;
logBox.ForeColor = Color.Black;
writeOutput = new WriteOutputDelegate(write);
}
public void server_recievedOutputStream(object sender, DataReceivedEventArgs args)
{
MessageBox.Show("Called window output!");
if (args.Data != null)
{
BeginInvoke(writeOutput, new object[] { args.Data.ToString() });
}
}
private void write(string output)
{
logBox.AppendText(output + Environment.NewLine);
}
}
}
Again the process works completely fine and with the UseShellExecute set to true I can see it is providing all information I need to grab. But when I set that to false its blank and I cant seem to grab any output data!
Thank you so much in advance... I've been at this for hours and hours...