日期:2014-05-17  浏览次数:21007 次

C# 得到命令行执行结果为空白,在线等指点
使用以下代码执行p1.exe程序,希望得到返回值
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";      
p.StartInfo.Arguments = "/c  p1.exe" ;           
p.StartInfo.UseShellExecute = false;            
p.StartInfo.RedirectStandardInput = true;              
p.StartInfo.RedirectStandardOutput = true;  
p.StartInfo.RedirectStandardError = true;  
p.StartInfo.CreateNoWindow = true;         
p.Start();          
string g = p.StandardOutput.ReadLine();
p.WaitForExit();
string Flag = p.StandardOutput.ReadLine();
MessageBox.Show(g + "  ew " + Flag + "  cc");
无论在
p.WaitForExit();
前后读取输出流,都是空白,不解?

p1.exe代码:
class Program
    {
        static int Main(string[] args)
        {
            int  kk = 998;
            System.Threading.Thread.Sleep(6000);
            return kk;
        }
    }
希望得到998返回值,环境:win7 x64 ,请指点

------解决方案--------------------
尼玛,p1.exe本来就什么都不显示,你能奢求它打印什么呢
------解决方案--------------------
Console.Write(kk);