好的,现在我有一个程序,它使用VB.net中的进程来运行FFmpeg。我在startinfo中发送进程参数以及文件位置等其他信息。当我运行代码时,它会将控制台输出发送到调试控制台;这可能是因为我设置了.UseShellExecute = False和processInfo.RedirectStandardOutput = True
我的问题是:我如何制作可以解释输出的东西?另外,对于FFmpeg,该进程是连续的,因此该进程在大部分时间内始终在运行,并不断地在调试控制台中添加更多的输出行。
我使用的代码如下:
Dim process As New Process
Dim processInfo As New ProcessStartInfo
processInfo.FileName = tempPath
processInfo.Arguments = ("-r 1/.1 -i " + link + " -c copy " + saveLocation + "\" + streamerName + ".ts")
processInfo.UseShellExecute = False
processInfo.WindowStyle = ProcessWindowStyle.Hidden
processInfo.CreateNoWindow = True
processInfo.RedirectStandardOutput = True
process.StartInfo = processInfo
process.Start()
我试过了,但没有成功。
Dim output As String
Using StreamReader As System.IO.StreamReader = process.StandardOutput
output = StreamReader.ReadToEnd().ToString
End Using
编辑:我现在有了这个代码:
Dim process As New Process
AddHandler process.OutputDataReceived, AddressOf CallbackProcesoAsync
AddHandler process.ErrorDataReceived, AddressOf ErrorDataReceivedAsync
Dim processInfo As New ProcessStartInfo
processInfo.FileName = tempPath
processInfo.Arguments = ("-r 1/.1 -i " + link + " -c copy " + saveLocation + "\" + streamerName + ".ts")
processInfo.UseShellExecute = False
processInfo.WindowStyle = ProcessWindowStyle.Hidden
processInfo.CreateNoWindow = False
processInfo.RedirectStandardOutput = True
processInfo.RedirectStandardError = True
process.StartInfo = processInfo
process.Start()
processes.Add(Tuple.Create(tempPath, streamerName))
Debug.WriteLine("Attempting to record " + streamerName)
Dim output As String
Using StreamReader As System.IO.StreamReader = process.StandardOutput
output = StreamReader.ReadToEnd().ToString
End Using
End If
End Sub
Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then
RichTextBox1.Text = args.Data
End If
End Sub
Private Sub ErrorDataReceivedAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then
RichTextBox2.Text = args.Data
End If
End Sub
但是我没有收到任何到richtextboxes的输出?
我觉得它和streamReader有关系,所以我把它移除了,但它还是不能工作?我不知道会是什么样子。
发布于 2017-09-20 05:53:05
Ffmpeg将所有调试信息输出到StdErr而不是StdOut。将RedirectStandardError设置为true并尝试从进程中读取StandardError。
https://stackoverflow.com/questions/46309460
复制相似问题