Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 来自Windows窗体控件的控制台输入_C#_Input_Process_Console - Fatal编程技术网

C# 来自Windows窗体控件的控制台输入

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

我正在创建一个应用程序,它接收来自控制台的输出,并使用windows窗体通过列表框以更用户友好的视图显示输出。我通过启动一个.jar文件的进程并使用以下代码完成了这项工作:

 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文件)。