zoukankan      html  css  js  c++  java
  • C#调用带参数并输出控制台的python的EXE程序

    private void button2_Click(object sender, EventArgs e)
    {
        using (Process process = new Process())
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
    
            //StartParameter
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C test2.exe 1 1024";
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardInput = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow = true;
            process.StartInfo = startInfo;
            process.OutputDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);
            process.Start();                
            process.WaitForExit();
            process.BeginOutputReadLine();
            //var strResult = process.StandardOutput.ReadToEnd();
            process.Close();
            //MessageBox.Show(strResult);
        }
    }
    public delegate void MyInvoke(string title);
    public void SetText(string title)
    {
        if (title == null) return;
        this.textBox1.AppendText(title + Environment.NewLine);
    }
    private void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine(e.Data);
        if (this.textBox1.InvokeRequired)
        {
            this.textBox1.Invoke(new MyInvoke(SetText), e.Data);
        }
        else
        {
            this.textBox1.AppendText(e.Data);
        }
    }

  • 相关阅读:
    第三次作业
    第二次作业
    第一次作业
    第五次作业
    第四次作业
    第三次作业
    刘存俊第二次作业
    数据压缩第一次作业
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/yansc/p/14037708.html
Copyright © 2011-2022 走看看