zoukankan      html  css  js  c++  java
  • C#学习(4)——使用shell调用外部exe应用

    一 首先创建一个windows窗体程序,在其中增加一个Button,以及一个TextBox

    二 接下来我们首先在命令提示行中调用我们之前就写过的HelloWorld

    C:UsersgaoDesktopHello.exe 代表我的Hello生成应用的位置,随后跟着的两个字符串代表Hello要使用的两个参数,之后enter既得到结果

    三 接下来就要使用Button将Hello.exe运行结果输出到TextBox里

    双击Button,添加代码

        private void button1_Click(object sender, EventArgs e)
            {
    
                Process process = new Process();
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.Start();
                string str = @"C:UsersgaoDesktopHello.exe"+" fengye C#";
           
                process.StandardInput.WriteLine(str);
                process.StandardInput.WriteLine("exit");
                string sh = process.StandardOutput.ReadToEnd();
                
    
                process.Close();
                this.textBox1.Text = sh;
               
            }
    

      运行结果如下:

    Author——峰烨

  • 相关阅读:
    PGA
    impdp导入job
    11g SQL Monitor
    Oracle buffer cache
    OGG异常处理
    Android中dp、dpi与px的关系
    android:gravity设置居中的问题
    Oracle触发器详解
    Android selector中的item的顺序
    selector在color和drawable目录下的区别
  • 原文地址:https://www.cnblogs.com/tjufengye/p/4396302.html
Copyright © 2011-2022 走看看