Redirecting Process Output : Process : Development C# Examples


C# Examples » Development » Process »

 

Redirecting Process Output









    
using  System;
using  System.Diagnostics;

class  MainClass
{
        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);        }
}
    
   
  
   



Output

Output:
 Volume in drive C has no label.
 Volume Serial Number is 8424-900C

 Directory of C:\Java_Dev\WEB\dev\CSharp

25/03/2007  12:31 PM               745 Abaseclassreferencecanrefertoaderivedclassobject.cs
25/03/2007  12:31 PM             3,435 AbetterwaytooverloadandforTwoDimension.cs
25/03/2007  12:34 PM               549 AbortaThread.cs
25/03/2007  12:37 PM               970 Aboutathread.cs


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Process