Csharp/CSharp Tutorial/Windows/Shell Process

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Starting a shell process: dir

<source lang="csharp">using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime; using System.Runtime.rupilerServices; using System.Security; using System.Text; using System.Threading; public class MainClass {

   public static void Main()
   {
       ProcessStartInfo pi = new ProcessStartInfo("dir.exe");
       pi.UseShellExecute = false;
       pi.RedirectStandardOutput = true;
       pi.Arguments = "C:\\";
       Process p = Process.Start(pi);
       StreamReader sr = p.StandardOutput;
       String line;
       while ((line = sr.ReadLine()) != null)
       {
           Console.WriteLine("Read line: {0}", line);
       }
       p.WaitForExit();
   }

}</source>