private void RunButton_Click(object sender, RoutedEventArgs e) { var index = this.ExecList.SelectedIndex; var program = files[index]; var file = this.FileName.Text; var output = System.IO.Path.Join(Directory.GetCurrentDirectory(), "outputs"); Directory.CreateDirectory(output); ProgramOutputs.Text = ""; ProgramOutputs.AppendText($"cmd.exe /C {program} {file} -O {output}"); var startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = $"/C {program} {file} -O {output}"; var process = new Process(); process.StartInfo = startInfo; process.OutputDataReceived += OnProgramOutputEvent; process.ErrorDataReceived += OnProgramErrorEvent; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); Thread thread = new Thread(MonitorProcess); thread.Start(process); }
private void OnProgramErrorEvent(object sender, DataReceivedEventArgs e) { var output = e.Data + Environment.NewLine; Dispatcher.BeginInvoke((Action)(() => { // ProgramOutputs.Foreground = Brushes.Red; ProgramOutputs.AppendText(output); })); }