C# 调用exe 并传参

    技术2022-05-19  19

     System.Diagnostics.Process p = new System.Diagnostics.Process();                 p.StartInfo = new System.Diagnostics.ProcessStartInfo();                 p.StartInfo.FileName = FilePath;                 Console.WriteLine("Input the command, Please");                 string strArgs = Console.ReadLine();                 p.StartInfo.Arguments = strArgs;//空格分隔各个参数 这里有两个参数。                 p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;                 p.StartInfo.RedirectStandardOutput = true;                 p.StartInfo.UseShellExecute = false;                 p.StartInfo.CreateNoWindow = true;//让窗体不显示

                    p.Start();

                    System.IO.StreamReader reader = p.StandardOutput;//截取输出流 ,如果exe中有Console.WriteLine("..")                       string outLine = reader.ReadLine();//每次读取一行

    另外一种是调用dos,并执行命令

                  string strIp = ConfigurationSettings.AppSettings["IP"].ToString();                string strPath = ConfigurationSettings.AppSettings["Path"].ToString();                string strAllData = ConfigurationSettings.AppSettings["AllData"].ToString();                string strArgs = string.Empty;                string strCmd = Console.ReadLine();

                    if (strCmd == "show")                {                    Console.WriteLine(strAllData);                }                else                {                    System.Diagnostics.Process p = new System.Diagnostics.Process();                    p.StartInfo.FileName = "cmd.exe";                    p.StartInfo.RedirectStandardInput = true;                    p.StartInfo.UseShellExecute = false;                    p.Start();                    p.StandardInput.WriteLine("rsh " + strIp + " " + strPath + " " + strCmd);                    p.Close();                }

     


    最新回复(0)