Posted by: Vinu Baby | August 27, 2008

Read the output of command line application from .NET C#

StreamWriter sw = new StreamWriter(“c:\\vinubaby\\cmdresult.txt”);
            System.Diagnostics.Process pr = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(“osql.exe”);
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;  
            info.CreateNoWindow = false;
            info.WorkingDirectory = @”c:\windows\system32″;

            pr.StartInfo = info;
            pr.Start();
            StreamReader sr = pr.StandardOutput;

            string ret = sr.ReadToEnd();
            sw.Write(ret);
            sw.Close();


Leave a response

Your response:

Categories