Redirecting Process Output : Process « Development « C# / CSharp Tutorial






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:
 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








14.15.Process
14.15.1.Starting Processes by using ProcessStartInfo
14.15.2.Starting a new process.
14.15.3.Detecting Process Completion
14.15.4.Redirecting Process Output
14.15.5.Get all processes on local machine
14.15.6.Enumerate over threads in a given PID
14.15.7.Enumerate over mods in a given PID
14.15.8.Launch / kill a process
14.15.9.Threads in Current Process
14.15.10.Property of current Process
14.15.11.Change priority for current process
14.15.12.List all process threads in current running processes
14.15.13.All current running processes
14.15.14.Listing processes on a remote machine
14.15.15.Get processes by name
14.15.16.Get all processes running on the local computer
14.15.17.Get all processes running on the remote computer
14.15.18.Get a process on the local computer, using the process id
14.15.19.Get a process on a remote computer, using the process id
14.15.20.Display the process statistics until the user closes the program
14.15.21.Uses the ProcessStartInfo class to start new processes, both in a minimized mode
14.15.22.Using an IP address to specify the machineName parameter
14.15.23.Start a Web page using a browser associated with .html and .asp files
14.15.24.Using the computer alias (do not precede with "\\")