zoukankan      html  css  js  c++  java
  • C#启动外部Exe控制台程序并输入命令

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    
    namespace ReNewCert
    {
        class Program
        {
            static void Main(string[] args)
            {
                Process p = new Process();
                //设置要启动的应用程序
                p.StartInfo.FileName = "C:\Desktop\wacs.exe";//是否使用操作系统shell启动
                p.StartInfo.UseShellExecute = false;
                // 接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardInput = true;
                //输出信息
                p.StartInfo.RedirectStandardOutput = true;
                // 输出错误
                p.StartInfo.RedirectStandardError = true;
                //不显示程序窗口
                p.StartInfo.CreateNoWindow = true ;
               
                //启动程序
                p.Start();
                Thread.Sleep(5000);
                //向cmd窗口发送输入信息
                p.StandardInput.WriteLine("R");
                p.StandardInput.WriteLine("exit");
                p.StandardInput.AutoFlush =true ;
                Thread.Sleep(5000);
                p.StandardInput.WriteLine("Q");
                p.StandardInput.WriteLine("exit");
                string strOuput = p.StandardOutput.ReadToEnd();
                //等待程序执行完退出进程
                p.WaitForExit();
                p.Close();
              
                Console.WriteLine(strOuput);            
            }
        }
    }
  • 相关阅读:
    json schema相关
    好看的记录片和电影
    java函数局部变量的坑(非常隐藏)
    maven操作
    Js数组的常用的方法概述
    深入理解JS各种this指向问题
    浅谈ES5和ES6继承和区别
    vue
    使用 vue-i18n 切换中英文
    js_数组对象的浅克隆
  • 原文地址:https://www.cnblogs.com/cdjbolg/p/12972229.html
Copyright © 2011-2022 走看看