Saving Standard Output in memory instead of a file in C#
<p>There is no online tutorial or even a book, for handling Standard Output with C#.</p>

<p>I want to save standard output in a variable (memory) instead of a file in Shell Execution.</p>

<p>This for storing thumbnail image from a video file with ffmpeg.</p>

<p>The below is my code.</p>

<pre><code>public static void GetThumbnail(string video, string thumbnail, string ffdir)
{
    var cmd = " -ss 00:01:00.000 -i " + '"' + video + '"' + " -vcodec rawvideo -vframes 1 -an -f rawvideo -s 320x240 pipe:1 ";


    var startInfo = new ProcessStartInfo
    {
        WindowStyle = ProcessWindowStyle.Normal,
        FileName = ffdir + "\\ffmpeg.exe ",
        Arguments = cmd,
        RedirectStandardOutput = true,
        UseShellExecute = false
    };

    var process = new Process
    {
        StartInfo = startInfo
    };

    process.OutputDataReceived += ProcessOnOutputDataReceived;
    process.ErrorDataReceived += ProcessOnOutputDataReceived;

    process.Start();

    process.WaitForExit(1000);
}

private static void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
{
    ....
}
</code></pre>

<p>But it does not enter to the event handler function (ProcessOnOutputDataReceived) when GetThumbnail function launched.</p>

<p>Is there any clue to solve this problem?</p>

<p>I referred the question and answer here:
<a href="https://stackoverflow.com/questions/25902443/getting-mulitple-images-from-a-single-stream-piped-from-ffmpeg-stdout">getting mulitple images from a single stream piped from ffmpeg stdout</a></p>

<p>But it does not help. It seems that the code for previous .NET versions.</p>