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);
    }
}

C#调用带参数并输出控制台的python的EXE程序

 

上一篇:C#如何将光标定位到文本框末尾(最后一位)


下一篇:PHP中替换换行符的几种方法小结【转】