为什么此方法不重定向 .exe [ffmpeg] 的输出?

发布于 2024-10-04 03:23:32 字数 1117 浏览 0 评论 0原文

我有方法:

public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit)
    {
        string retMessage = "";

        using (Process p = new Process())
        {
            p.StartInfo.FileName = exePathArg;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.Arguments = argumentsArg;
            p.StartInfo.UseShellExecute = false;



            try
            {
                p.Start();
                StreamReader myOutput = p.StandardOutput;

                retMessage = "STANDARD OUTPUT: " +  myOutput.ReadToEnd();

                p.WaitForExit(timeToWaitForProcessToExit);
            }
            catch (Exception ex)
            { 
                retMessage = "EXCEPTION THROWN: " + ex.ToString();

            }
            finally
            {
                try
                {
                    p.Kill();
                }
                catch { }
            }
        }

        return retMessage;
    }

但它不会将我的输出重定向到 retMessage。有人有什么想法吗?我测试了bat文件中的参数,输出肯定是输出。

干杯, 皮特

I have the method:

public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit)
    {
        string retMessage = "";

        using (Process p = new Process())
        {
            p.StartInfo.FileName = exePathArg;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.Arguments = argumentsArg;
            p.StartInfo.UseShellExecute = false;



            try
            {
                p.Start();
                StreamReader myOutput = p.StandardOutput;

                retMessage = "STANDARD OUTPUT: " +  myOutput.ReadToEnd();

                p.WaitForExit(timeToWaitForProcessToExit);
            }
            catch (Exception ex)
            { 
                retMessage = "EXCEPTION THROWN: " + ex.ToString();

            }
            finally
            {
                try
                {
                    p.Kill();
                }
                catch { }
            }
        }

        return retMessage;
    }

But it doesnt redirect my output to retMessage. Anyone any ideas? I tested the arguments in a bat file and output is definitely output.

Cheers,
Pete

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似最初 2024-10-11 03:23:32

我的猜测(同意dtb的评论):
AFAIK ffmpeg 使用 stdout 来输出二进制数据(多媒体、快照等),而 stderr 用于记录目的。在您的示例中,您使用标准输出。

因此,将代码更改为:

    p.StartInfo.RedirectStandardError = true;
    ...
    string log = p.StandardError.ReadToEnd();

它应该可以解决您的问题。

My guess (agree with dtb's comment):
AFAIK ffmpeg uses stdout to pipe out binary data(multimedia, snapshots, etc.) and stderr is used for logging purposes. In your example you use stdout.

So, change you code to:

    p.StartInfo.RedirectStandardError = true;
    ...
    string log = p.StandardError.ReadToEnd();

and it should solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文