.NET调用EXE方法

一、EXE调用使用方法

通过.NET 中的Process对EXE文件进行调用,可以模拟输入,获得输出与错误输出。

这里贴下试用的代码:

//test for process

           Process prc = new Process();


           try

           {

               prc.StartInfo.FileName = "F:\\e1.exe";

               prc.StartInfo.UseShellExecute = false;

               //输入输出重定向

               prc.StartInfo.RedirectStandardError = true;

               prc.StartInfo.RedirectStandardInput = true;

               prc.StartInfo.RedirectStandardOutput = true;

               prc.StartInfo.CreateNoWindow = false;

               prc.Start();

               //获得输出

               string output = prc.StandardOutput.ReadLine();

               Console.WriteLine("e1 success");

               Console.WriteLine(output);

           }

           catch (Exception ex)

           {

               if (!prc.HasExited)

               {

                   prc.Close();

               }

               Console.WriteLine("e1 failed");

               throw new Exception(ex.Message.ToString());

           }


你可能感兴趣的:(.NET调用EXE方法)