gpt4 book ai didi

vb.net - 如何与流程输出交互?

转载 作者:行者123 更新时间:2023-12-04 23:26:15 24 4
gpt4 key购买 nike

好的,所以目前我有一个使用 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有关,所以我删除了它,但它仍然不起作用?我不知道它可能是什么。

最佳答案

Ffmpeg 将所有调试信息输出到 StdErr 而不是 StdOut。使用 RedirectStandardError 为 true 并尝试从进程中读取 StandardError。

关于vb.net - 如何与流程输出交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46309460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com