I am currently working on a program, that can handle Minecraft servers. I am running my batch witch logs the server, and i now want the batch (called batch in my code) to log in my listbox called lg_log.
If it is possible, how can I do that?
I am programming in visual studio – Windows forms in c#.
Edit: This is my code:
Process batch = new Process();
string PathtoRunFile = @"\Servers\Base\start_server.bat";
string current_directory = Directory.GetCurrentDirectory();
string server_base = @"\Servers\Base";
string working_directory = current_directory + server_base;
batch.StartInfo.FileName = current_directory + PathtoRunFile;
batch.StartInfo.Arguments = "";
batch.StartInfo.WorkingDirectory = working_directory;
batch.StartInfo.UseShellExecute = true;
batch.Start();
The
Process.StartInfocontains properties likeRedirectStandardOutput. By setting this flag totrue, you will be able to add an event handler tobatch.StartInfo.OutputDataReceivedand listen for any events. Somewhat like so:Edit: You might also want to enable redirecting the ErrorOutput in order to receive error messages.
Edit: As requested, here is a fully working example. Make sure that
test.batexists.