Redirecting Process Output

using System;
using System.Diagnostics;

public class RedirectingProcessOutput
{
    public static void Main()
    {
        Process p = new Process();
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.Arguments = "/c dir *.cs";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.Start();
        
        string output = p.StandardOutput.ReadToEnd();
        
        Console.WriteLine("Output:");
        Console.WriteLine(output);    
    }
}

 

More Informations see this page : http://www.java2s.com/Code/CSharp/Development-Class/StartAndKillProcess.htm


posted on 2009-12-23 22:50  风Na  阅读(122)  评论(0编辑  收藏  举报

导航