Why doesn't this method redirect my output from .exe [ffmpeg]?

I have a 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 does not redirect my output to retMessage. Any ideas? I tested the arguments in the bat file and the output is definitely output.

Cheers, Pete

+5
source share
1 answer

My guess (I agree with the dtb comment): AFAIK ffmpeguses stdout to output binary data (multimedia, snapshots, etc.), and stderr is used for logging. In your example, you are using stdout.

So change the code:

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

and he should solve your problem.

+8
source

All Articles