Hallo,
ich packe mit der 7z.exe mit meinem Programm (große) Archive...
Wenn man den Befehl direkt in der Konsole ausführt, wird während des Packens der Fortschritt in Prozent angezeigt.
Den Konsoleninhalt muss ich jetzt irgendwie auslesen um den Fortschritt rauszufiltern. Wichtig ist, dass das Konsolenfenster dabei nicht sichtbar ist.
Bisher benutze ich den Code von hier. Mein Code sieht so aus:
Das Funktioniert zwar, aber der Konsoleninhalt wird erst ausgegeben, wenn die Konsolenanwendung fertig ist. Ich möchte die Konsole aber "live" auslesen, während sie noch arbeitet.
Kennt da jemand eine Lösung?
Vielen Dank
ich packe mit der 7z.exe mit meinem Programm (große) Archive...
Wenn man den Befehl direkt in der Konsole ausführt, wird während des Packens der Fortschritt in Prozent angezeigt.
Den Konsoleninhalt muss ich jetzt irgendwie auslesen um den Fortschritt rauszufiltern. Wichtig ist, dass das Konsolenfenster dabei nicht sichtbar ist.
Bisher benutze ich den Code von hier. Mein Code sieht so aus:
VB.NET-Quellcode
- Private Sub bgw_zip_DoWork(.......)
- 'Pfad zur 7z.exe
- SevenZip.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory & "7z.exe"
- 'Parameter für die 7z-Konsole
- SevenZip.StartInfo.Arguments = parameter
- ' kein Window erzeugen
- SevenZip.StartInfo.CreateNoWindow = True
- ' UseShellExecute auf falsch setzen
- SevenZip.StartInfo.UseShellExecute = False
- ' StandardOutput von Console umleiten
- SevenZip.StartInfo.RedirectStandardOutput = True
- ' Eventhandler für Redirection definieren
- AddHandler SevenZip.OutputDataReceived, AddressOf WriteProcessOutput
- ' Prozess starten
- SevenZip.Start()
- ' Asynchrones Lesen starten
- SevenZip.BeginOutputReadLine()
- SevenZip.Start()
- 'Wartet bis 7-Zip fertig ist (=automat. geschlossen wurde)
- SevenZip.WaitForExit()
- End Sub
- ' EventHandler Routine für umgeleiteten Output
- Private Sub WriteProcessOutput(.....)
- ' Daten kommen nicht auf GUI Thread -> per anonymer Methode Invoken
- If outLine.Data IsNot Nothing Then
- TextBox1.Dispatcher.Invoke(Sub() TextBox1.AppendText(outLine.Data & Environment.NewLine))
- End If
- End Sub
Das Funktioniert zwar, aber der Konsoleninhalt wird erst ausgegeben, wenn die Konsolenanwendung fertig ist. Ich möchte die Konsole aber "live" auslesen, während sie noch arbeitet.
Kennt da jemand eine Lösung?
Vielen Dank