Click here to Skip to main content
15,902,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

VB
Dim pathmviasf As String = "c:\Aio-Pdf-Batch\Movies\Asf\"
Dim pathmvitmp As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\Bmp\"


VB
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
Posted
Updated 15-Feb-10 6:44am
v3

The Start method returns a handle to the process, you can then wait for it to end.
 
Share this answer
 
you could use the WaitForExit() method on the ffmPeg Process object

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit%28VS.71%29.aspx[^]

Given WaitForExit() can be an indefinite wait, I'd make sure to add a kill button to your code and use the Kill() method, so they can kill it if they get bored.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900