Maby this helps you ^^
Make a textbox and name it: "serverlog" for output data from server
Make a textbox and name it: "msgtb" to write commands to server
Make a button and name it: "Startbt" to Start the server
Make a button and name it: "Stopbt" to stop the server
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace MinecraftServer
{
public partial class MinecraftServer : Form
{
StreamWriter WriteCommands;
BackgroundWorker StartServer = new BackgroundWorker();
delegate void SetTextCallBack(string text);
string MaxRam = "1024";
string MinRam = "1024";
string server = @"C:\Users\LetsPlayLittle\Desktop\server\server.jar";
public MinecraftServer()
{
InitializeComponent();
StartServer.DoWork += StartServer_DoWork;
}
void StartServer_DoWork(object sender, DoWorkEventArgs e)
{
for (var i = 0; i < 1; i++)
{
Process Minecraft = new Process();
Minecraft.StartInfo.FileName = "CMD.exe";
Minecraft.StartInfo.CreateNoWindow = false;
Minecraft.StartInfo.RedirectStandardInput = true;
Minecraft.StartInfo.RedirectStandardOutput = true;
Minecraft.StartInfo.RedirectStandardError = true;
Minecraft.StartInfo.UseShellExecute = false;
Minecraft.OutputDataReceived += Minecraft_OutputDataReceived;
Minecraft.ErrorDataReceived += Minecraft_ErrorDataReceived;
Minecraft.Start();
Minecraft.BeginOutputReadLine();
Minecraft.BeginErrorReadLine();
WriteCommands = Minecraft.StandardInput;
WriteCommands.WriteLineAsync(@"java -Xmx" + MaxRam + "M -Xms" + MinRam + "M -jar " + server + " " + "nogui");
}
}
void Minecraft_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
}
void Minecraft_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
this.SetText(msgtb.Text + e.Data + System.Environment.NewLine);
}
catch (Exception ex)
{
}
}
private void SetText(string text)
{
if (this.serverlog.InvokeRequired)
{
SetTextCallBack d = new SetTextCallBack(SetText);
this.Invoke(d, new object[] { text });
}
else
{
serverlog.Text += text + System.Environment.NewLine;
}
}
private void Startbt_Click(object sender, EventArgs e)
{
StartServer.RunWorkerAsync();
}
private void Stopbt_Click(object sender, EventArgs e)
{
WriteCommands.WriteLineAsync("/stop");
}
private void msgtb_Enter(object sender, EventArgs e)
{
WriteCommands.WriteLineAsync(msgtb.Text);
}
}
}