-
Aug 15th, 2021, 05:02 PM
#1
Thread Starter
Lively Member
Help! I want to send process output to textbox in realtime.
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 redirecting the process output to a textbox, I can't see what it's doing until it's done:
Code:
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
-
Aug 15th, 2021, 09:09 PM
#2
Re: Help! I want to send process output to textbox in realtime.
You are calling ReadToEnd on your StreamReader. How exactly do you think that works? If you're going to read to the end of a stream then there has to be an end to read to, i.e. the method won't return until the stream has been closed, i.e. when the process has completed. If you want to display the output as it becomes available then you have to read it as it becomes available.
-
Aug 15th, 2021, 09:38 PM
#3
Thread Starter
Lively Member
Re: Help! I want to send process output to textbox in realtime.
Okay, that makes sense. But I'm not sure what other method to use and still have the command work.
TIA
-
Aug 15th, 2021, 09:54 PM
#4
Re: Help! I want to send process output to textbox in realtime.
Why wouldn't you call ReadLine in a loop, just as is often done when reading files? I've never tried it but I would assume that it would work in exactly the same way.
-
Aug 16th, 2021, 06:04 AM
#5
Thread Starter
Lively Member
Re: Help! I want to send process output to textbox in realtime.
Thx for the reply.
I'm compressing a folder (which contains data & images) into a zip file. I don't believe that can be done reading the source folder "a line at a time" (one "line" would have to be the entire 500K binary file.)
UPDATE: Someone on another site found the answer. I had to switch from older "7za.exe" to newer "7z.exe" and use the "-bs" switch ("-bsp1").
Last edited by Mugsy323; Aug 16th, 2021 at 09:06 AM.
-
Aug 16th, 2021, 07:24 AM
#6
Re: Help! I want to send process output to textbox in realtime.
By one line he means one line of the output stream not the folder.
-
Aug 16th, 2021, 09:08 AM
#7
Thread Starter
Lively Member
Re: Help! I want to send process output to textbox in realtime.
Thanks. See "Update" above. Solution was to use a newer version of 7zip which includes a switch that supports what I'm trying to do.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|