过程调用中退出条件的结果不同

时间:2017-08-31 09:39:57

标签: vb.net ffmpeg

作为项目的一小部分,我正在调用ffmpeg来转换视频 - 我使用的是一个旧示例,它使用了一些输出来创建一个挂起的进度条。代码如下:

[initiation code common to both examples]
    Dim inputFile, outputFile As String, myProcess As New Process
    Dim psiProcInfo As New ProcessStartInfo, ffreader As StreamReader


    inputFile = "C:\Users\mklefass\Downloads\Video 2017-08-16 21.01.39.mov"
    outputFile = "C:\Users\mklefass\Downloads\tmp2\Output"

    psiProcInfo.FileName = Application.StartupPath + "\ffmpeg.exe"  'Location Of FFMPEG.EXE
    psiProcInfo.Arguments = " -i " & Chr(34) & inputFile & Chr(34) & " -vf fps=5 " & Chr(34) & outputFile & "%d.jpg" & Chr(34)                              'start ffmpeg with command strFFCMD string
    psiProcInfo.UseShellExecute = False                             'use the shell execute command we always want no
    psiProcInfo.WindowStyle = ProcessWindowStyle.Hidden             'hide the ffmpeg process window
    psiProcInfo.RedirectStandardError = True                        'Redirect the error out so we can read it
    psiProcInfo.RedirectStandardOutput = True                       'Redirect the standard out so we can read it
    psiProcInfo.CreateNoWindow = True

[bit that changes]
myProcess.Start()
ffreader = myProcess.StandardError
Do
    Try
        If Not myProcess.HasExited Then
            'Debug.WriteLine(ffreader.ReadLine)
        End If
    Catch
        If Not myProcess.HasExited Then
            MsgBox("Something went wrong")
        End If
    End Try
Loop Until myProcess.HasExited
MsgBox("done")

然后我找到另一个只调用可执行文件的例子,然后在完成时继续 - 如下所示:

[same initialisation]
Debug.WriteLine("Starting...")
myProcess.Start()
strOutput = myProcess.StandardError.ReadToEnd
myProcess.WaitForExit()
myProcess.Close()

Debug.Write(strOutput)
MsgBox("done")

第二种方法运作得很好......"退出状态"有什么不同? Process.HasExitedProcess.WaitForExit寻找?

0 个答案:

没有答案