private void StartProgramRun() { try { _currentProgram = new Process(); _currentProgram.StartInfo.FileName = $"mypath"; _currentProgram.StartInfo.RedirectStandardInput = true; _currentProgram.StartInfo.RedirectStandardOutput = true; _currentProgram.StartInfo.RedirectStandardError = true; _currentProgram.StartInfo.UseShellExecute = false; _currentProgram.EnableRaisingEvents = true; _currentProgram.Exited += CurrentProgram_Exited; _currentProgram.OutputDataReceived += CurrentProgram_OutputDataReceived; _currentProgram.ErrorDataReceived += CurrentProgram_OutputDataReceived; _currentProgram.Start(); _currentProgram.BeginOutputReadLine(); _currentProgram.BeginErrorReadLine(); } catch (Exception ex) { _currentChannel.SendMessageAsync("Error on ProcessStart: " + ex.Message); } } private void CurrentProgram_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Data)) { //displays the message to the user } } private void CurrentProgram_Exited(object sender, EventArgs e) { //displays that the program exited and deletes the executable File.Delete($"mypath"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)