zoukankan      html  css  js  c++  java
  • 在C#中调用EXE文件

    1. 如果exe文件的返回值是int类型,标识操作执行的结果是否成功,例如:

    class Program

        {

            static int Main(string[] args)

            {

                return args.Length;

            }

     }

    则在调用exe文件时,可以用如下方法:

    Process myProcess = new Process();

    string fileName = @"C:/Test.exe";

    string para =@"你好 北京欢迎你!";

    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, para);

    myProcess.StartInfo = myProcessStartInfo;

    myProcess.Start();

    while (!myProcess.HasExited)

    {

       myProcess.WaitForExit();

    }

    int returnValue = myProcess.ExitCode;

     

    2. 如果exe文件是将输出内容写入标准流,例如:

    class Program

        {

            static void Main(string[] args)

            {

                Console.Write(args[0] + args[1] + args [2]);           

            }

     }

    则在调用exe文件时,可以用如下方法:

    string fileName = @"C:/Test.exe";

    Process p = new Process();

    p.StartInfo.UseShellExecute = false;

    p.StartInfo.RedirectStandardOutput = true;

    p.StartInfo.FileName = fileName;

    p.StartInfo.CreateNoWindow = true;

    p.StartInfo.Arguments = "你好, 北京 欢迎你!";//参数以空格分隔,如果某个参数为空,可以传入””

    p.Start();

    p.WaitForExit();

    string output = p.StandardOutput.ReadToEnd();

  • 相关阅读:
    使用srvany.exe将任何程序作为Windows服务运行
    instsrv.exe用法
    在博客园中发现的一篇文章,感觉这些内容就是我心中所想表达的!
    HTML5的Video标签的属性,方法和事件汇总
    使用nodejs 来压缩整个目录
    git 基础
    mac 上安装 redis
    第12次实验总结
    第12次实验作业
    第十一次实验总结
  • 原文地址:https://www.cnblogs.com/xiaoyusmile/p/2280911.html
Copyright © 2011-2022 走看看