Beispiel #1
0
        //---------------------------------------------------------------------------------
        /// <summary>
        /// Run the command asynchrounously and return the console output
        /// </summary>
        //---------------------------------------------------------------------------------
        public Task <ToolOutput> RunAsync(params string[] args)
        {
            return(Task.Run(() =>
            {
                var output = new ToolOutput();
                var process = new Process();
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.OutputDataReceived += (sender, eventsArgs) => output.AddStdOut(eventsArgs.Data);
                process.ErrorDataReceived += (sender, eventsArgs) => output.AddStdError(eventsArgs.Data);
                process.StartInfo.Arguments = string.Join(" ", args);
                process.StartInfo.FileName = Path;

                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
                process.CancelOutputRead();
                return output;
            }));
        }