Annotation of cleanflash/CleanFlashCommon/ProcessRunner.cs, revision 1.1.1.1

1.1       root        1: using System.Diagnostics;
                      2: using System.Text;
                      3: 
                      4: namespace CleanFlashCommon {
                      5:     public class ProcessRunner {
                      6: 
                      7:         public static ExitedProcess RunProcess(ProcessStartInfo startInfo) {
                      8:             startInfo.RedirectStandardOutput = true;
                      9:             startInfo.RedirectStandardError = true;
                     10: 
                     11:             StringBuilder outputBuilder = new StringBuilder();
                     12:             Process process = new Process {
                     13:                 StartInfo = startInfo
                     14:             };
                     15:             DataReceivedEventHandler outputHandler = new DataReceivedEventHandler(
                     16:                 delegate (object sender, DataReceivedEventArgs e) {
                     17:                     outputBuilder.AppendLine(e.Data);
                     18:                 }
                     19:             );
                     20: 
                     21:             process.OutputDataReceived += outputHandler;
                     22:             process.ErrorDataReceived += outputHandler;
                     23: 
                     24:             process.Start();
                     25:             process.BeginOutputReadLine();
                     26:             process.BeginErrorReadLine();
                     27:             process.WaitForExit();
                     28:             process.CancelOutputRead();
                     29:             process.CancelErrorRead();
                     30: 
                     31:             return new ExitedProcess {
                     32:                 ExitCode = process.ExitCode,
                     33:                 Output = outputBuilder.ToString().Trim()
                     34:             };
                     35:         }
                     36: 
                     37:         public static Process RunUnmanagedProcess(ProcessStartInfo startInfo) {
                     38:             Process process = new Process {
                     39:                 StartInfo = startInfo
                     40:             };
                     41:             process.Start();
                     42:             process.WaitForExit();
                     43:             return process;
                     44:         }
                     45:     }
                     46: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.