File:  [cleanflash] / cleanflash / CleanFlashCommon / ProcessRunner.cs
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed Oct 13 09:04:22 2021 UTC (4 years, 7 months ago) by root
Branches: UNKNWN, MAIN
CVS tags: v3400192, HEAD
cleanflash 34.0.0.192

using System.Diagnostics;
using System.Text;

namespace CleanFlashCommon {
    public class ProcessRunner {

        public static ExitedProcess RunProcess(ProcessStartInfo startInfo) {
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;

            StringBuilder outputBuilder = new StringBuilder();
            Process process = new Process {
                StartInfo = startInfo
            };
            DataReceivedEventHandler outputHandler = new DataReceivedEventHandler(
                delegate (object sender, DataReceivedEventArgs e) {
                    outputBuilder.AppendLine(e.Data);
                }
            );

            process.OutputDataReceived += outputHandler;
            process.ErrorDataReceived += outputHandler;

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            process.CancelOutputRead();
            process.CancelErrorRead();

            return new ExitedProcess {
                ExitCode = process.ExitCode,
                Output = outputBuilder.ToString().Trim()
            };
        }

        public static Process RunUnmanagedProcess(ProcessStartInfo startInfo) {
            Process process = new Process {
                StartInfo = startInfo
            };
            process.Start();
            process.WaitForExit();
            return process;
        }
    }
}

unix.superglobalmegacorp.com

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