public async Task <List <string> > RunAsync(string arguments) { Process process = new Process(); process.StartInfo.FileName = _execute_filename; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; process.StartInfo.CreateNoWindow = true; process.StartInfo.WorkingDirectory = _working_directory; StringArrayOutput output = new StringArrayOutput(); process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { output.OnOutput(e.Data); }; process.EnableRaisingEvents = true; process.Start(); if (_useDebugOutput) { Debug.WriteLine($"arguments: {arguments}"); } process.BeginOutputReadLine(); await Task.Run(() => process.WaitForExit()); return(output.GetResult()); }
private void InitializeProcess() { process_ = new Process(); process_.StartInfo.FileName = filename_; process_.StartInfo.Arguments = command_; process_.StartInfo.UseShellExecute = false; process_.StartInfo.RedirectStandardInput = true; process_.StartInfo.RedirectStandardOutput = true; process_.StartInfo.RedirectStandardError = true; process_.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; process_.StartInfo.CreateNoWindow = true; process_.StartInfo.WorkingDirectory = repository_path_; StringArrayOutput output = new StringArrayOutput(); process_.OutputDataReceived += (object _, DataReceivedEventArgs console_output) => { if (console_output.Data == null) { AddOutputText("---------- Process Exited ----------"); return; } AddOutputText(console_output.Data); }; process_.ErrorDataReceived += (object _, DataReceivedEventArgs error_output) => { if (error_output.Data == null) { return; } AddOutputText(error_output.Data); }; process_.Exited += (object sender, EventArgs e) => { if (button.Dispatcher.CheckAccess()) { Process_Exited(); } else { button.Dispatcher.BeginInvoke(new Action(() => { Process_Exited(); })); } }; process_.EnableRaisingEvents = true; }
public List<string> Run(string arguments) { Process process = new Process(); process.StartInfo.FileName = execute_filename_; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; process.StartInfo.CreateNoWindow = true; process.StartInfo.WorkingDirectory = working_directory_; StringArrayOutput output = new StringArrayOutput(); process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { output.OnOutput(e.Data); }; process.EnableRaisingEvents = true; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); return output.GetResult(); }