问题描述
我试图从我的我的Minecraft服务器控制台输出到控制台gui
有什么建议吗?
Im trying to get output from my minecraft server console to by console gui
any suggestions?
private void button_start_Click(object sender, EventArgs e)
{
this.button_start.Enabled = false;
using (Process sortProcess = new Process())
{
sortProcess.StartInfo.FileName = @"C:\Users\Nico Travassos\Desktop\Minecraft\Minecraft CROSS Server\RUN.bat";
sortProcess.StartInfo.CreateNoWindow = true;
sortProcess.StartInfo.UseShellExecute = false;
sortProcess.StartInfo.RedirectStandardOutput = true;
// Set event handler
sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
// Start the process.
sortProcess.Start();
// Start the asynchronous read
sortProcess.BeginOutputReadLine();
sortProcess.WaitForExit();
}
}
void SortOutputHandler(object sender, DataReceivedEventArgs e)
{
Trace.WriteLine(e.Data);
this.BeginInvoke(new MethodInvoker(() =>
{
richTextBox1.AppendText(e.Data ?? string.Empty);
}));
}
尝试使用我定制的gui运行我的Minecraft服务器,但每次点击开始它都会启动运行.bat并给出错误错误:无法访问jarfile craftbukkit.jar
这是我的运行文件代码。
Trying to run my minecraft server in my custom gui i made but every time i click start its starts the RUN.bat and gives a error "Error: unable access jarfile craftbukkit.jar"
this is my run file code.
@ECHO OFF
"C:\Program Files (x86)\Java\jre7\bin\java.exe" -Xmx1024M -Xms512M -Xmn256M -XX:+UseParNewGC -XX:+DisableExplicitGC -XX:+UseFastAccessorMethods -XX:+UseConcMarkSweepGC -XX:UseSSE=3 -XX:ParallelGCThreads=2 -jar craftbukkit-1.6.4-R1.0.jar nogui
PAUSE
推荐答案
craftbukkit-1.6.4-R1.0.jar
?不,那是严厉措辞 - jre如何知道在哪里找到那个jar - 它是在你的CLASSPATH上,还是,你在java.exe运行语句中为实例指定了一个CLASSPATH?
我看到人们开始流程的最常见错误是他们认为环境就像他们登录时一样 - 除非你真的强迫流程在不同的流程下运行配置文件,该配置文件已正确设置,通常不是这样的情况
'g'
in relation to your exe ? no, thats badly phrased - how will the jre know where to find that jar - is it on your CLASSPATH, or, have you specified a CLASSPATH in your java.exe run statement for-instance ?
The commonest mistake I see where people are starting 'processes' is they assume the environment is as they see it when they are logged on - and unless you're actually forcing the process to be run under a different profile, and that profile has everything set up correctly, thats usually not the case
'g'
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);
}
}
}
这篇关于C#我试图从我的我的Minecraft服务器控制台输出到我的自定义gui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!