I am stuck in a problem in calling a command-line application through a button-click code.
the application is ffmpeg.
my application is to convert pdf docs to images to movie files.
I first create a temp directory for copying images, and then call ffmpeg with the arguments of input (folder), output - file name
i use for each loop for accessing different directories entered in a listbox. then for each directory i call ffmpeg.exe.
now comes the problem, for each directory in listbox i create a bmp folder
then i call ffmpeg , convert the images to movie, and delete the folder. What i want is the folder to be deleted only when the process has exited, because the folder gets deleted in midway and not all the images are converted.
How do i know when the process has exited after completing the conversion?
Dim pathmviasf As String = "c:\Aio-Pdf-Batch\Movies\Asf\"
Dim pathmvitmp As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\Bmp\"
For cnt As Integer = 0 To ListBoxControl1.Items.Count - 1
If Directory.Exists(pathmvitmp) Then
Directory.Delete(pathmvitmp, True)
Directory.CreateDirectory(pathmvitmp)
Else
Directory.CreateDirectory(pathmvitmp)
End If
Dim i As Integer
pdffile1 = PDFFile.Open(ListBoxControl1.Items(cnt))
For i = 0 To pdffile1.PageCount - 1
Dim pageImage As Bitmap = pdffile1.GetPageImage(i, 96)
pageImage.Save(String.Format(pathmvitmp & "page{0}.bmp", i), ImageFormat.Bmp)
Next i
strfil = pathmviasf & IO.Path.GetFileNameWithoutExtension(ListBoxControl1.Items(cnt)) & "\"
If Not Directory.Exists(strfil) Then
Directory.CreateDirectory(strfil)
Else
Directory.Delete(strfil, True)
Directory.CreateDirectory(strfil)
End If
Dim videoPath As String = strfil & IO.Path.GetFileNameWithoutExtension(ListBoxControl1.Items(cnt)) & ".asf"
Dim ffmpeg As Process = New Process()
ffmpeg.StartInfo.RedirectStandardOutput = True
ffmpeg.StartInfo.UseShellExecute = False
ffmpeg.StartInfo.Arguments = String.Format(videoPath & " " & 0.5)
ffmpeg.StartInfo.FileName = "ffmpeg.exe"
ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ffmpeg.Start()
Next