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

  • 相关阅读:
    react-dnd例子代码学习记录
    GitKraken使用记录
    Table-dnd-tree代码分析
    umi-request请求码200,但是response是网页
    MyBatis-Plus配置输出日志
    PAT甲级1021解法
    PAT甲级1020解法
    PAT甲级1019解法
    PAT甲级1017解法
    PAT甲级1018解法
  • 原文地址:https://www.cnblogs.com/yansc/p/14037708.html
Copyright © 2011-2022 走看看