首页 > 编程语言 > 详细

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

时间:2020-11-25 22:32:06      阅读:84      评论:0      收藏:0      [点我收藏+]

 

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程序

原文:https://www.cnblogs.com/yansc/p/14037708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!