Redirecting Output
Synergi
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
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
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