The below code is working fine for ping stackoverflow.com
and most other cases but when I using 7z.exe it's not real time, it waits until directory is compressed and then shows the output. The argument that I used for compress is a test.7z dirpath
. Can I do anything else?
private ProcessStartInfo GetProcessStartInfo(string filename, string arguments)
{
ProcessStartInfo ProcessStartInfo = new ProcessStartInfo();
ProcessStartInfo.CreateNoWindow = true;
ProcessStartInfo.UseShellExecute = false;
ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ProcessStartInfo.RedirectStandardOutput = true;
ProcessStartInfo.RedirectStandardError = true;
ProcessStartInfo.RedirectStandardInput = true;
ProcessStartInfo.FileName = filename;
ProcessStartInfo.Arguments = arguments;
}
private void ProcessRun(string filename, string arguments)
{
Process Process = new Process();
Process.StartInfo = GetProcessStartInfo(filename, arguments);
Process.ErrorDataReceived += Process_OutputDataReceived;
Process.OutputDataReceived += Process_OutputDataReceived;
Process.EnableRaisingEvents = true;
Process.Start();
Process.BeginOutputReadLine();
Process.BeginErrorReadLine();
Process.WaitForExit();
}
public ObservableList<string> Output = new ObservableList<string>();
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Output.Add(e.Data);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
OutputListBox.ItemsSource = Output;
ProcessRun("cmd.exe", "/c ping stackoverflow.com");
}
7zip Output:
7zip Progress: