有一个C++程序 编译后生成 a.exe main()函数的返回值为1,即 return 1. 
有Process运行它,如何取得返回值?
谢谢!!

解决方案 »

  1.   

    呵呵,查看它的Process.ExitCode;属性。
      

  2.   

            private static string runcmd(string command)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = "/c " + command;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                return p.StandardOutput.ReadToEnd();
            }string s=runcmd("a.exe");  //s="1"
      

  3.   

    Process.ExitCode 得到的是-8******,很大的一个负数。
      

  4.   

    Process.ExitCode得到的是一个很大的负数。