Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesnt this method redirect my output from .exe [ffmpeg]?

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

like image 335
Exitos Avatar asked Nov 22 '10 15:11

Exitos


1 Answers

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.

like image 182
Oleks Avatar answered Nov 09 '22 18:11

Oleks