C# 来自Windows窗体控件的控制台输入
我正在创建一个应用程序,它接收来自控制台的输出,并使用windows窗体通过列表框以更用户友好的视图显示输出。我通过启动一个.jar文件的进程并使用以下代码完成了这项工作:C# 来自Windows窗体控件的控制台输入,c#,input,process,console,C#,Input,Process,Console,我正在创建一个应用程序,它接收来自控制台的输出,并使用windows窗体通过列表框以更用户友好的视图显示输出。我通过启动一个.jar文件的进程并使用以下代码完成了这项工作: public void DataReceived(object sender, DataReceivedEventArgs e) { // e.Data is the line which was written to standard output if (e.Data != nu
public void DataReceived(object sender, DataReceivedEventArgs e)
{
// e.Data is the line which was written to standard output
if (e.Data != null)
{
// textBox1.Invoke((MethodInvoker)delegate { textBox1.Text = textBox1.Text + e.Data; });
Invoke(new MethodInvoker(delegate { listBox1.Items.Add(e.Data); }));
}
}
public void StartServer()
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("java", @"-Xmx1024M -jar " + UltimateMinecraftServerCreator.Properties.Settings.Default.jarname);
p.StartInfo.WorkingDirectory = UltimateMinecraftServerCreator.Properties.Settings.Default.jarlocator;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += DataReceived;
p.Start();
p.BeginOutputReadLine();
}
我想知道,在同一个表单上,是否允许用户单击将向控制台发送命令的按钮,以及如果知道可以键入命令
谢谢 终于解决了!实际上非常简单,我将进程p的声明移到了所有控件代码之上,因此它变得通用,并且能够使用p.StandardInput.WriteLine(“”) 不太清楚,你有两个申请吗?一个是windows窗体,另一个是控制台应用程序?或者您只有win forms应用程序并从命令行运行它?抱歉!基本上,我已经创建了一个windows窗体应用程序,我正在通过我的应用程序运行一个.jar文件,并将其输出到一个列表框中,但是我希望能够调用正在运行的服务器并允许将数据输出到它。所以从本质上讲,它确实像一个控制台一样运行,但我没有创建它(即.jar文件)。