韩言福地

只有想不到的,没有办不到的。 - HY Auspicious Place

« 让Windows程序只启动一个实例,第二个实例启动激活第一个实例 C#程序如何接受命令行参数 »

启动子进程,等待子进程结束,并获得输出

   启动子进程,等待子进程结束,并获得输出

 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
    psi.RedirectStandardOutput = true;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     psi.UseShellExecute = false;
     System.Diagnostics.Process listFiles;
     listFiles = System.Diagnostics.Process.Start(psi);
     System.IO.StreamReader myOutput = listFiles.StandardOutput;
    listFiles.WaitForExit(2000);
   
    if (listFiles.HasExited) 
    { 
        string output = myOutput.ReadToEnd(); 
        this.processResults.Text = output;
    }

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Copyright 2007-2010 www.yinrg.com(HY Auspicious Place) . 湘ICP备06007796号.