Redirecting Output

SynergiSynergi Join Date: 2012-11-07 Member: 167921Members
<div class="IPBDescription">Redirecting Output of Server.exe doesn't work ???</div>Hi Community,

i have another problemm. I want to build a Server Manager for NS2 and more features afterwards. But for this, the bread & butter feature is to hook the Server.exe. For this the easiest way is to redirect the Output of the Server.exe and make my own manager for all the console windows.

So but here comes mmy problem. I can redirect the content but the stream is empty in the end. And i really dont know why? As an explanation, imm a c# Developer and im really familiar with c# so the code cant be the problem i use this to redirect all console windows, but here is the code snippet which does the job:

private Process serverExe;
private StreamWriter serverExeInput;

public MainWindow()
{
InitializeComponent();

this.Closing += MainWindow_Closing;

this.StartServer();
}

void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.serverExe.Kill();
}

private void StartServer()
{
ProcessStartInfo serverInfo = new ProcessStartInfo();
serverInfo.FileName = "E:\\steam\\SteamApps\\common\\Natural Selection 2\\Server.exe";
serverInfo.Arguments = "-name \"Test\"";
serverInfo.UseShellExecute = false;
serverInfo.ErrorDialog = true;
serverInfo.CreateNoWindow = true;
serverInfo.RedirectStandardError = true;
serverInfo.RedirectStandardInput = true;
serverInfo.RedirectStandardOutput = true;

this.serverExe = new Process();
this.serverExe.StartInfo = serverInfo;
this.serverExe.OutputDataReceived += new DataReceivedEventHandler(ServerExeOutputReceived);
this.serverExe.ErrorDataReceived += new DataReceivedEventHandler(ServerExeErrorReceived);
this.serverExe.Start();

this.serverExeInput = this.serverExe.StandardInput;

this.serverExe.BeginOutputReadLine();
}

private void ServerExeOutputReceived(object sender, DataReceivedEventArgs args)
{
if(!String.IsNullOrEmpty(args.Data))
{
this.WriteOutput(args.Data);
}
}

private void ServerExeErrorReceived(object sender, DataReceivedEventArgs args)
{
if (!String.IsNullOrEmpty(args.Data))
{
this.WriteOutput(args.Data);
}
}

private void WriteOutput(string msg)
{
Dispatcher.BeginInvoke(new Action(() => this.txb_content.Text += msg + Environment.NewLine));
}

The event is never raised. And my question is -> WHY THE HELL. I cant understand it.

Pls help -> if i can get a solution for this a server manager will be released of me under GNU\GPL so everyone can use it.

tia Synergi

Comments

  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    This has not worked since one of the beta patches. I spent a long time trying to find a solution, and have determined it's not really possible.
  • SynergiSynergi Join Date: 2012-11-07 Member: 167921Members
    Can u pls explain what u find out that this is impossible???

    I cant really understand it. It doesn't matter if they used c, c++, c#, vb or what ever to do this console output. Cout, Console.Writeline, printf, >>, all writes into a Stream. The Console only displays this stream. And we are only redirecting this output. Thats all. There is no reason for not working.

    When u make the window visible and still redirect the output u can see that it is redirected anywhere, because the console window keeps to stay blank. But where does the data land???

    sr but im totally confused of this.

    tia Synergi
  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    It lands in a magical place. I don't know why it's so broken, only that it is. I used to read out the console via a similar method in Python, and one of the builds came along and broke it. I suspect it has something to do with them not flushing the buffer after every line anymore, but I cannot say for certain.
  • SynergiSynergi Join Date: 2012-11-07 Member: 167921Members
    Ok, sounds really weird but possible x) Could a developer pls be so kind and say sth to this !!! This feature is the bread& butter of every real server manager, and i really want to develop sth but i need to get the feature to redirect output of the Server.exe.
Sign In or Register to comment.