For 7za, you must redirect the progress line with the flag -bsp, like :
-bsp1
I did a test in C# in the Console, same thing in VB :
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a program that processes a collection of files, places them in a folder, and then compresses that folder using a CLI-based exe. Works fine.
Problem is, during the compression, despite redircting the process output to a textbox, I can't see what it is doing until it's done:
Private Sub ZipFolder()
Dim sOutput As String
Dim oProcess As New Process
' Compress/Zip:
With oProcess.StartInfo
.FileName = Chr(34) & strLaunchDir & "\7za.exe" & Chr(34)
.Arguments = "a -tzip " & Chr(34) & Path.GetDirectoryName(strCTKPath) & "\" & lblFolderName.Text & "\Folders\" & lblFolderName.Text & ".zip" & Chr(34) & " " & Chr(34) & Path.GetDirectoryName(strCTKPath) & "\" & lblFolderName.Text & "\Folders\" & lblFolderName.Text & Chr(34) ' Command format: "7za.exe a [zip switch] "Dest" "Src"
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True ' use this if you don`t want to see the cmd window.
End With
oProcess.Start()
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
tbxOutput.AppendText(sOutput) ' Append output w/o reassigning/printing the entire contents over & over. "Append" forces window to scroll.
Application.DoEvents() ' This gives labels time to update so it doesn't freeze during the process.
tbxOutput.Refresh() ' Do this to update window in realtime.
End Using
oProcess.WaitForExit()
oProcess.Close()
oProcess.Dispose()
End Sub
>
I thought "tbxOutput.Refresh()" would be enough, but clearly it isn't.
Is there a way to show the process output so I can see the compression taking place in real-time? TIA
UPDATE: I've learned the issue is related to "oStreamReader.ReadToEnd()", but I don't know how else to read/process an archive if not read in full first (or what other method to use instead... I assume in a loop... until [what]?
For 7za, you must redirect the progress line with the flag -bsp, like :
-bsp1
I did a test in C# in the Console, same thing in VB :
Hi @Mugsy's RapSheet ,
Is there a way to show the process output so I can see the compression taking place in real-time?
Take a look at the following code.
...
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
While Not oStreamReader.EndOfStream
Dim line As String = oStreamReader.ReadLine()
tbxOutput.AppendText(line)
...
End While
...
End Using
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thanks for the reply!
<strike>When you say "redirect the progress line", what line would that be? "-bsp" or "-bsp1" aren't valid 7za switches, so I'm not sure where to place it.</strike>
Wait, still looking into it. "-bs" switch exists in "7z.exe" (not "7za.exe".)
And is this using Xingyu's "oStreamReader.ReadLine()" or my original "oStreamReader.ReadToEnd()" method?
TIA