Starting a shell process: dir : Shell Process « Windows « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime;
using System.Runtime.CompilerServices;
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();
    }
}








29.7.Shell Process
29.7.1.Starting a shell process: dir