Run the command line process and get the result while this process is still running?

How can I start a command line process and get output while this process is still running?

What I mean is to start the CLI process with its own progress indicator, the executable itself takes a lot of time to complete the operation, so I want to take this progress information from my own process to show the progress in my application, otherwise I have no information to display the progress until the process is complete.

I am working on a WindowsForm project, not a console application.

I tried to do the same using FFMPEG.exe (x64) and I can read the “progress” while FFMPEG is running, I can select the progress from FFMPEG and do what I want, but with this executable I just can’t do this to do, and I don't know if this is possible.

The program "dbPowerAmp CoreConverter" is a music converter, I think the program sends all outputs in Unicode encoding, because to read the output I need to set the output encoding to Unicode.

... Another problem is that I cannot find a way to read the StandardError output of this process even using Unicode, so if someone can help me with these two problems.

Here is the application: http://www.dbpoweramp.com/install/dMC-R14.4-Ref-Trial.exe

Here is an example of output from a program launched directly from CMD:

enter image description here

(I need to select the number of characters "*" stars "progress" during the process to calculate and display this percentage in my application)

And here is my code:

Private Shared CoreConverter As New Process() Private Shared CoreConverter_Info As New ProcessStartInfo() With { _ .CreateNoWindow = True, _ .UseShellExecute = False, _ .RedirectStandardOutput = True, _ .RedirectStandardError = True _ } Private Shared Sub Run_CoreConverter() ' Just for testing CMD Unicode output: ' ' CoreConverter_Info.FileName = "cmd" ' CoreConverter_Info.Arguments = "/U /CC:\CoreConverter.exe " & CoreConverter_Info.Arguments CoreConverter_Info.FileName = "C:\CoreConverter.exe" CoreConverter_Info.Arguments = String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""mp3 (Lame)""" ..., blah blah blah) CoreConverter_Info.StandardErrorEncoding = System.Text.Encoding.Unicode CoreConverter_Info.StandardOutputEncoding = System.Text.Encoding.Unicode CoreConverter.StartInfo = CoreConverter_Info CoreConverter.EnableRaisingEvents = True CoreConverter.Start() CoreConverter.WaitForExit() Dim readerStdOut As IO.StreamReader = CoreConverter.StandardOutput ' This part works with FFMPEG executable but not with Coreconverter.exe, ' What I mean is that the msgbox is displayed when CoreConverter.exe finishes :( ' but with FFMPEG I can read the output while FFMPEG still running. While CoreConverter.StandardOutput.EndOfStream = True MsgBox(CoreConverter.StandardOutput.ReadLine) End While If CoreConverter.ExitCode <> 0 Then ' Throw New Exception(CoreConverter.StandardError.ReadToEnd) ' No way to read the ErrorOutput... MessageBox.Show(CoreConverter.StandardError.ReadToEnd, "CoreConverter", MessageBoxButtons.OK, MessageBoxIcon.Error) MessageBox.Show(CoreConverter.StandardOutput.ReadToEnd, "CoreConverter", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub 

UPDATE:

In fact, I am so desperate, all my intentions are epic, I tried everything that my skills can do (but this is not so much).

Even using multithread to start a process in a separate thread, while I try to get output from the main thread, I can’t try to extract the result of the process until the process ends, it's crazy !, I don’t understand why it happens.

It's just a crazy thing, when I lose many hours a day, some people tell me that it’s possible to make a COM object, I can do it, well, I don’t want to learn for many months how to make a COM object to select a couple of characters from the console. This is a month-long training that would not help me in anything else in my life, just like that, I need something more basic, maybe the idea of ​​reading a buffer console can work, but of course I could not read the buffer until then until the process is complete, therefore.

So. What can I do with this damn process?

Just to do more than update my question, to say my own words of desesperation, I will insert here the multithreaded thing I tried.

... As I said, I can’t try to read the outputs while the process is still running, and the error output is simply impossible to read (the line is always empty), even when the process ends (with the intent of an error).

 Public Shared error_output As String Public Shared standard_output As String Public Shared active As Boolean = False ' CoreConverter Thread is active? Public Shared MyThread As Threading.Thread = New Threading.Thread(AddressOf Run_CoreConverter) Public Shared Sub Convert_To_MP3(ByVal In_File As String, _ ' blah blah blah 'Run_CoreConverter() MyThread = New Threading.Thread(AddressOf Run_CoreConverter) ' MyThread.IsBackground = True active = True MyThread.Start() Get_Output() End Sub Public Shared Sub Get_Output() While active ' While Coreconverter.exe is runing... Try If Not CoreConverter.HasExited Then MsgBox(CoreConverter.StandardOutput.ReadToEnd) ' This will not be displayed until process has exited... End If Catch ex As Exception End Try If error_output IsNot Nothing Then MsgBox(error_output) ' This will not be displayed until process has exited... End If If standard_output IsNot Nothing Then MsgBox(standard_output) ' This will not be displayed until process has exited... End If End While MsgBox("end active") End Sub Public Shared Sub Run_CoreConverter() CoreConverter_Info.FileName = CoreConverter_Location CoreConverter_Info.StandardErrorEncoding = System.Text.Encoding.Unicode CoreConverter_Info.StandardOutputEncoding = System.Text.Encoding.Unicode CoreConverter.StartInfo = CoreConverter_Info CoreConverter.EnableRaisingEvents = False CoreConverter.Start() ' CoreConverter.WaitForExit() ' Threading.Thread.Sleep(2000) ' For x As Integer = 0 To 99999999 error_output = CoreConverter.StandardError.ReadToEnd standard_output = CoreConverter.StandardOutput.ReadToEnd ' Next If CoreConverter.ExitCode <> 0 Then Throw New Exception(CoreConverter.StandardError.ReadToEnd) MessageBox.Show(CoreConverter.StandardError.ReadToEnd, "CoreConverter", MessageBoxButtons.OK, MessageBoxIcon.Error) MessageBox.Show(CoreConverter.StandardOutput.ReadToEnd, "CoreConverter", MessageBoxButtons.OK, MessageBoxIcon.Error) End If CoreConverter.Close() active = False End Sub 
+6
source share
3 answers

I think there may be errors in the dbPowerAmp encoding. The result looks great in the cmd.exe / u Unicode environment, but it seems that when the .Net Process object is connected, it ends with zero bytes between characters. You can get around this by discarding null bytes between good UTF8 characters.

I own more PowerShell, so here is what I wrote to prove that this will work.

 $progressCounter = 0.0 $progressScaleString = "0%-----------25%-----------50%-----------75%-----------100%" $psi = new-object system.diagnostics.processstartinfo $psi.FileName = "C:\Program Files (x86)\Illustrate\dBpoweramp\CoreConverter.exe" # Moby Dick audiobook available at <http://ia600208.us.archive.org/0/items/moby_dick_librivox/mobydick_135_melville.mp3> $psi.arguments = '-infile="C:\AudioBooks\mobydick_135_melville.mp3" -outfile="c:\AudioBooks\mobydick_135_melville.flac" -convert_to="flac" -encoding="SLOW"' $psi.StandardOutputEncoding = [System.Text.Encoding]::Unicode $psi.RedirectStandardOutput = $true $psi.UseShellExecute = $false $proc = new-object System.Diagnostics.Process $proc.StartInfo = $psi $proc.Start(); #Look for the magic progress bar string $outputBuf = "" while($true){ $chr = [char]$proc.StandardOutput.BaseStream.ReadByte(); if($chr -ne [char]0){ $outputBuf += $chr; } if($outputBuf.Contains($progressScaleString)){ break; }else{ sleep .01; }} #We've seen the progress ruler, now start counting the pips. while($progressCounter -le 100.0){ $chr = $proc.StandardOutput.BaseStream.ReadByte(); if($chr -lt 0){break;} if([char]$chr -eq [char]"*"){ $progressCounter += 100.0/($progressScaleString.Length+1); write-host $progressCounter; }} 

Here is my crack when porting this to VB; Just run it on the workflow and hook PercentDone to your user interface:

 Public Event PercentDone(ByVal Percent As Float) Private Shared CoreConverter As New Process() Private Shared CoreConverter_Info As New ProcessStartInfo() With { _ .CreateNoWindow = True, _ .UseShellExecute = False, _ .RedirectStandardOutput = True, _ .RedirectStandardError = True _ } Private Shared Sub Run_CoreConverter() Dim ProgressScaleString As String = "0%-----------25%-----------50%-----------75%-----------100%" Dim ProgressCounter As Float = 0.0 CoreConverter_Info.FileName = "C:\CoreConverter.exe" CoreConverter_Info.Arguments = String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""mp3 (Lame)""" ..., blah blah blah) CoreConverter_Info.StandardErrorEncoding = System.Text.Encoding.Unicode CoreConverter_Info.StandardOutputEncoding = System.Text.Encoding.Unicode CoreConverter.StartInfo = CoreConverter_Info CoreConverter.Start() Dim OutputBuf As String = "" Dim chr As Byte; While True chr = CoreConverter.StandardOutput.BaseStream.ReadByte(); If chr < 0 Then Exit While ElseIf chr <> 0 OutputBuf += CType(chr, Char) End If If OutputBuf.Contains(ProgressScaleString) Then Exit While Else System.Threading.Thread.Sleep(10) End If End While While ProgressCounter <= 100 chr = CoreConverter.StandardOutput.BaseStream.ReadByte() If chr <= 0 Then Exit While End If If chr == CType("*"C, Char) Then ProgressCounter += 100.0/($progressScaleString.Length+1) RaiseEvent PercentDone(ProgressCounter) End If End While End Sub 
+5
source

The process writes a string of stars (*). I can check the redirection of output to a file ( >out.txt ). You should use CoreConverter.StandardOutput.Read .

Let's have a form with a multi-line TextBox named txtResult and a cmdStart button:

 Private Sub cmdStart_Click(sender As Object, e As EventArgs) Handles cmdStart.Click Dim ProcInfo As New ProcessStartInfo With {.FileName = "C:\dbpower\dBpoweramp\CoreConverter.exe", .RedirectStandardOutput = True, .UseShellExecute = False, .WorkingDirectory = "C:\dbpower\dBpoweramp", .Arguments = "-infile=""0.mp3"" -outfile=""1.mp3"" -convert_to=""mp3 (lame)"""} ' Dim proc As Process = Process.Start(ProcInfo) Dim counter As Integer = 0 While Not proc.HasExited Dim a As String = ChrW(proc.StandardOutput.Read) If a = "*" Then counter += 1 txtResult.Text = counter Application.DoEvents() End If Threading.Thread.Sleep(3) Application.DoEvents() End While End Sub 

Progress is recorded in the TextBox as numbers 1-59. You can easily convert it to a progress bar. Plase don't forget to change the .exe path.

+3
source

Finally, this is what I did to solve the problem, in order to get both outputs in a "simple way":

 #Region " Process Info " ' CoreConverter Process Information. Private Shared CoreConverter As New Process() With { _ .StartInfo = New ProcessStartInfo With { _ .CreateNoWindow = True, _ .UseShellExecute = False, _ .RedirectStandardError = True, _ .RedirectStandardOutput = True, _ .StandardErrorEncoding = System.Text.Encoding.Unicode, _ .StandardOutputEncoding = System.Text.Encoding.Unicode}} #End Region ' Some code ' Blah blah blah... #Region " Run Converter Procedure " Private Shared Sub Run_CoreConverter() CoreConverter.StartInfo.FileName = CoreConverter_Location CoreConverter.Start() While Not CoreConverter.HasExited OutputCharacter = ChrW(CoreConverter.StandardOutput.Read) If OutputCharacter = "*" Then CurrentProgress += 1 ' Maximum value is 59, so a ProgressBar Maximum property value would be 59. RaiseEvent PercentDone(CurrentProgress, Nothing) End If If CurrentProgress = 59 Then ' I store only the last line 'cause it has interesting information: ' Example message: Conversion completed in 30 seconds x44 realtime encoding StandardOutput = CoreConverter.StandardOutput.ReadToEnd.Trim End If End While ErrorOutput = CoreConverter.StandardError.ReadToEnd Select Case CoreConverter.ExitCode Case 0 : RaiseEvent Exited(StandardOutput, Nothing) ' Return StandardOutput Case Else : RaiseEvent Exited(ErrorOutput, Nothing) ' Return ErrordOutput End Select CurrentProgress = 0 OutputCharacter = Nothing StandardOutput = Nothing ErrorOutput = Nothing ' CoreConverter.Close() End Sub #End Region 

UPDATE:

Here is the full class if anyone needs it:

 #Region " CoreConverter Helper " ' [ CoreConverter Helper ] ' ' // By Elektro H@cker ' ' ' Instructions: ' ' 1. Add the "CoreConverter.exe" into the project, ' together with the dbPoweramp Effects and Codec folders. ' ' Examples : ' ' ------------------- ' CONVERT FILE TO MP3 ' ------------------- ' CoreConverter.Convert_To_MP3("C:\Input.wav", "C:\Output.mp3", _ ' CoreConverter.Lame_Bitrate.kbps_320, _ ' CoreConverter.Lame_Bitrate_Mode.cbr, _ ' CoreConverter.Lame_Profile.SLOW, _ ' CoreConverter.Lame_Quality.Q0_Maximum, _ ' CoreConverter.Lame_Khz.Same_As_Source, _ ' CoreConverter.Lame_Channels.auto, _ ' { _ ' CoreConverter.DSP_Effects.Delete_Output_File_on_Error, _ ' CoreConverter.DSP_Effects.Recycle_Source_File_After_Conversion _ ' }, _ ' False, _ ' CoreConverter.Priority.normal) ' ' ------------------- ' CONVERT FILE TO WAV ' ------------------- ' CoreConverter.Convert_To_WAV_Uncompressed("C:\Input.mp3", "C:\Output.wav", _ ' CoreConverter.WAV_Uncompressed_Bitrate.Same_As_Source, _ ' CoreConverter.WAV_Uncompressed_Khz.Same_As_Source, _ ' CoreConverter.WAV_Uncompressed_Channels.Same_As_Source, , False) ' ' ------------------- ' CONVERT FILE TO WMA ' ------------------- ' CoreConverter.Convert_To_WMA("C:\Input.mp3", "C:\Output.wma", _ ' CoreConverter.WMA_9_2_BitRates.Kbps_128, _ ' CoreConverter.WMA_9_2_Khz.Khz_44, _ ' CoreConverter.WMA_9_2_Channels.stereo, , False) ' ' ------ ' EVENTS ' ------ ' Public WithEvents Converter As New CoreConverter() ' ' Sub Converter_Progress(Progress As Integer, e As EventArgs) Handles Converter.PercentDone ' ProgressBar1.Maximum = 59 ' ProgressBar1.Step = 1 ' ProgressBar1.PerformStep() ' End Sub ' ' Sub Converter_Message(Message As String, e As EventArgs) Handles Converter.Exited ' ProgressBar1.Value = 0 ' MessageBox.Show(Message) ' End Sub Public Class CoreConverter : Implements IDisposable #Region " Variables " ' <summary> ' Gets or sets CoreConverter.exe executable path. ' </summary> Public Shared CoreConverter_Location As String = ".\CoreConverter.exe" ' Stores the CoreConverter process progress Private Shared CurrentProgress As Integer = 0 ' Stores the CoreConverter process StandarOutput Private Shared StandardOutput As String = String.Empty ' Stores the CoreConverter process ErrorOutput Private Shared ErrorOutput As String = String.Empty ' Stores the next output character Private Shared OutputCharacter As Char = Nothing ' Stores the DSP Effects formatted string Private Shared Effects As String = String.Empty #End Region #Region " Events " ' <summary> ' Event raised when conversion progress changes. ' </summary> Public Shared Event PercentDone As EventHandler(Of PercentDoneEventArgs) Public Class PercentDoneEventArgs : Inherits EventArgs Public Property Progress As Integer End Class ' <summary> ' Event raised when CoreConverter process has exited. ' </summary> Public Shared Event Exited As EventHandler(Of ExitedEventArgs) Public Class ExitedEventArgs : Inherits EventArgs Public Property Message As String End Class #End Region #Region " Process Info " ' CoreConverter Process Information. Private Shared CoreConverter As New Process() With { _ .StartInfo = New ProcessStartInfo With { _ .CreateNoWindow = True, _ .UseShellExecute = False, _ .RedirectStandardError = True, _ .RedirectStandardOutput = True, _ .StandardErrorEncoding = System.Text.Encoding.Unicode, _ .StandardOutputEncoding = System.Text.Encoding.Unicode}} #End Region #Region " CoreConverter Enumerations " ' Priority level of CoreConverter.exe Enum Priority idle low normal high End Enum ' DSP Effects Public Enum DSP_Effects Delete_Output_File_on_Error ' Delete failed conversion (not deletes source file). Delete_Source_File_After_Conversion ' Delete source file after conversion. Recycle_Source_File_After_Conversion ' Send source file to recycle bin after conversion. Karaoke_Remove_Voice ' Remove voice from file. Karaoke_Remove_Instrument ' Remove instruments from file. Reverse ' Reverse complete audio file. Write_Silence ' Write silence at start of file. End Enum #End Region #Region " Codec Enumerations " Enum Lame_Bitrate kbps_8 = 8 kbps_16 = 16 kbps_24 = 24 kbps_32 = 32 kbps_40 = 40 kbps_48 = 48 kbps_56 = 56 kbps_64 = 64 kbps_80 = 80 kbps_96 = 96 kbps_112 = 112 kbps_128 = 128 kbps_144 = 144 kbps_160 = 160 kbps_192 = 192 kbps_224 = 224 kbps_256 = 256 kbps_320 = 320 End Enum Enum Lame_Bitrate_Mode cbr abr End Enum Enum Lame_Profile NORMAL FAST SLOW End Enum Enum Lame_Quality Q0_Maximum = 0 Q1 = 1 Q2 = 2 Q3 = 3 Q4 = 4 Q5 = 5 Q6 = 6 Q7 = 7 Q8 = 8 Q9_Minimum = 9 End Enum Enum Lame_Khz Same_As_Source khz_8 = 8000 khz_11 = 11000 khz_12 = 12000 khz_16 = 16000 khz_22 = 22000 khz_24 = 24000 khz_32 = 32000 khz_44 = 44100 khz_48 = 48000 End Enum Enum Lame_Channels auto mono stereo joint_stereo forced_joint_stereo forced_stereo dual_channels End Enum Enum WAV_Uncompressed_Bitrate Same_As_Source bits_8 = 8 bits_16 = 16 bits_24 = 24 bits_32 = 32 End Enum Enum WAV_Uncompressed_Khz Same_As_Source khz_8 = 8000 khz_11 = 11000 khz_12 = 12000 khz_16 = 16000 khz_22 = 22000 khz_24 = 24000 khz_32 = 32000 khz_44 = 44100 khz_48 = 48000 khz_96 = 96000 khz_192 = 192000 End Enum Enum WAV_Uncompressed_Channels Same_As_Source Channels_1_Mono = 1 Channels_2_Stereo = 2 Channels_3 = 3 Channels_4_Quadraphonic = 4 Channels_5_Surround = 5 Channels_6_Surround_DVD = 6 Channels_7 = 7 Channels_8_Theater = 8 End Enum Enum WMA_9_2_BitRates Kbps_12 = 12 Kbps_16 = 16 Kbps_20 = 20 Kbps_22 = 22 Kbps_24 = 24 Kbps_32 = 32 Kbps_40 = 40 Kbps_48 = 48 Kbps_64 = 64 Kbps_80 = 80 Kbps_96 = 96 Kbps_128 = 128 Kbps_160 = 160 Kbps_192 = 192 Kbps_256 = 256 Kbps_320 = 320 End Enum Enum WMA_9_2_Khz Khz_8 = 8 Khz_16 = 16 Khz_22 = 22 Khz_32 = 32 Khz_44 = 44 Khz_48 = 48 End Enum Enum WMA_9_2_Channels mono stereo End Enum #End Region #Region " Codec Procedures " #Region " MP3 Lame " ' <summary> ' Converts a file to MP3 using Lame codec. ' </summary> Public Shared Sub Convert_To_MP3(ByVal In_File As String, _ ByVal Out_File As String, _ ByVal Bitrate As Lame_Bitrate, _ ByVal Bitrate_Mode As Lame_Bitrate_Mode, _ ByVal Encoding_Profile As Lame_Profile, _ ByVal Quality As Lame_Quality, _ ByVal Khz As Lame_Khz, _ ByVal Channels As Lame_Channels, _ Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _ Optional ByVal Update_Tag As Boolean = True, _ Optional ByVal Priority As Priority = Priority.normal, _ Optional ByVal Processor As Short = 1) If DSP_Effects IsNot Nothing Then Effects = String.Empty For X As Integer = 0 To DSP_Effects.Length - 1 Effects &= String.Format(" -dspeffect{0}={1}", _ X + 1, _ Format_DSP_Effect(DSP_Effects(X).ToString)) Next End If CoreConverter.StartInfo.Arguments = String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""mp3 (Lame)"" {2} {3} -priority=""{4}"" -processor=""{5}"" -b {6} {7} -encoding=""{8}"" -freq=""{9}"" -channels=""{10}"" --noreplaygain --extracli=""-q {11}""", _ In_File, _ Out_File, _ If(Not Update_Tag, "-noidtag", ""), _ Effects, _ Priority.ToString, _ Processor, _ CInt(Bitrate), _ "--" & Bitrate_Mode.ToString, _ Encoding_Profile.ToString, _ If(Khz = Lame_Khz.Same_As_Source, "", CInt(Khz)), _ If(Channels = Lame_Channels.auto, "", Channels), _ CInt(Quality)) Run_CoreConverter() End Sub #End Region #Region " WAV Uncompressed " ' <summary> ' Converts a file to WAV ' </summary> Public Shared Sub Convert_To_WAV_Uncompressed(ByVal In_File As String, _ ByVal Out_File As String, _ ByVal Bitrate As WAV_Uncompressed_Bitrate, _ ByVal Khz As WAV_Uncompressed_Khz, _ ByVal Channels As WAV_Uncompressed_Channels, _ Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _ Optional ByVal Update_Tag As Boolean = True, _ Optional ByVal Priority As Priority = Priority.normal, _ Optional ByVal Processor As Short = 1) If DSP_Effects IsNot Nothing Then Effects = String.Empty For X As Integer = 0 To DSP_Effects.Length - 1 Effects &= String.Format(" -dspeffect{0}={1}", _ X + 1, _ Format_DSP_Effect(DSP_Effects(X).ToString)) Next End If CoreConverter.StartInfo.Arguments = String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""Wave"" {2} {3} -priority=""{4}"" -processor=""{5}"" -compression=""PCM"" -bits=""{6}"" -freq=""{7}"" -channels=""{8}""", _ In_File, _ Out_File, _ If(Not Update_Tag, "-noidtag", ""), _ Effects, _ Priority.ToString, _ Processor, _ If(Bitrate = WAV_Uncompressed_Bitrate.Same_As_Source, "", CInt(Bitrate)), _ If(Khz = WAV_Uncompressed_Khz.Same_As_Source, "", CInt(Khz)), _ If(Channels = WAV_Uncompressed_Channels.Same_As_Source, "", CInt(Channels))) Run_CoreConverter() End Sub #End Region #Region " WMA 9.2 " ' <summary> ' Converts a file to WMA 9.2 ' </summary> Public Shared Sub Convert_To_WMA(ByVal In_File As String, _ ByVal Out_File As String, _ ByVal Bitrate As WMA_9_2_BitRates, _ ByVal Khz As WMA_9_2_Khz, _ ByVal Channels As WMA_9_2_Channels, _ Optional ByVal DSP_Effects() As DSP_Effects = Nothing, _ Optional ByVal Update_Tag As Boolean = True, _ Optional ByVal Priority As Priority = Priority.normal, _ Optional ByVal Processor As Short = 1, _ Optional ByVal LogFile As String = ".\CoreConverter.log") If DSP_Effects IsNot Nothing Then Effects = String.Empty For X As Integer = 0 To DSP_Effects.Length - 1 Effects &= String.Format(" -dspeffect{0}={1}", _ X + 1, _ Format_DSP_Effect(DSP_Effects(X).ToString)) Next End If CoreConverter.StartInfo.Arguments = String.Format("-infile=""{0}"" -outfile=""{1}"" -convert_to=""Windows Media Audio 10"" {2} {3} -priority=""{4}"" -processor=""{5}"" -codec=""Windows Media Audio 9.2"" -settings=""{6} kbps, {7} kHz, {8} CBR""", In_File, _ Out_File, _ If(Not Update_Tag, "-noidtag", ""), _ Effects, _ Priority.ToString, _ Processor, _ CInt(Bitrate), _ CInt(Khz), _ Channels.ToString) Run_CoreConverter() End Sub #End Region #End Region #Region " Run Converter Procedure " Private Shared Sub Run_CoreConverter() CoreConverter.StartInfo.FileName = CoreConverter_Location CoreConverter.Start() While Not CoreConverter.HasExited OutputCharacter = ChrW(CoreConverter.StandardOutput.Read) If OutputCharacter = "*" Then CurrentProgress += 1 ' Maximum value is 59, so a ProgressBar Maximum property value would be 59. RaiseEvent PercentDone(CurrentProgress, Nothing) End If If CurrentProgress = 59 Then ' I store only the last line 'cause it has interesting information: ' Example message: Conversion completed in 30 seconds x44 realtime encoding StandardOutput = CoreConverter.StandardOutput.ReadToEnd.Trim End If End While ' Stores the Error Message (If any) ErrorOutput = CoreConverter.StandardError.ReadToEnd Select Case CoreConverter.ExitCode Case 0 : RaiseEvent Exited(StandardOutput, Nothing) ' Return StandardOutput Case Else : RaiseEvent Exited(ErrorOutput, Nothing) ' Return ErrordOutput End Select CurrentProgress = 0 OutputCharacter = Nothing StandardOutput = Nothing ErrorOutput = Nothing CoreConverter.Close() End Sub #End Region #Region " Miscellaneous functions " ' <summary> ' Checks if CoreConverter process is avaliable. ' </summary> Public Shared Function Is_Avaliable() As Boolean Return IO.File.Exists(CoreConverter_Location) End Function ' Returns the DSP Effects formatted string Private Shared Function Format_DSP_Effect(ByVal Effect As String) Select Case Effect Case "Reverse" : Return """Reverse""" Case "Delete_Output_File_on_Error" : Return """Delete Destination File on Error=""" Case "Recycle_Source_File_After_Conversion" : Return """Delete Source File=-recycle""" Case "Delete_Source_File_After_Conversion" : Return """Delete Source File=""" Case "Karaoke_Remove_Voice" : Return """Karaoke (Voice_ Instrument Removal)=""" Case "Karaoke_Remove_Instrument" : Return """Karaoke (Voice_ Instrument Removal)=-i""" Case "Write_Silence" : Return """Write Silence=-lengthms={qt}2000{qt}""" ' 2 seconds Case Else : Return String.Empty End Select End Function #End Region #Region " Dispose Objects " Public Sub Dispose() Implements IDisposable.Dispose ' CoreConverter_Location = Nothing ' Don't touch OutputCharacter = Nothing StandardOutput = Nothing ErrorOutput = Nothing CurrentProgress = Nothing Effects = Nothing CoreConverter.Close() GC.SuppressFinalize(Me) End Sub #End Region End Class #End Region 
+1
source

Source: https://habr.com/ru/post/955218/


All Articles