0

I am working on a c# program to loop over my Windows Media Center recorded TV shows (.wtv) and convert them using the handbrake cli. I just got everything to work now and I wanted to also utilize the --scan function so that I can customize the audio and video arguments based on the input file rather then set a static.

This is what I have so far for the scan but I can't seem to find where the data is that prints out to the console window.

var p = new Process();
var pSI = new ProcessStartInfo();
pSI.RedirectStandardOutput = true;
pSI.UseShellExecute = false;
pSI.FileName = HandBrakeLocation;
pSI.Arguments = string.Concat(@"--scan -i ", '"', inputFile, '"');
pSI.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo = pSI;
p.Start();
var stdout = p.StandardOutput;//streamreader
p.WaitForExit();

I thought that perhaps the p.StandardOutput would send the console output to the stdout StreamReader variable, but I could not find it anywhere inside the object. What am i missing?

Thanks for you time and assistance.

user3071434
  • 133
  • 1
  • 2
  • 13

1 Answers1

0

You can read the program output using the StandardOutput property of the process (which is a stream):

var output = stdout.ReadToEnd();
p.WaitForExit();

More info can be found on MSDN: https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput%28v=vs.110%29.aspx

Sven Vranckx
  • 374
  • 4
  • 5
  • Thanks, but I tried that and the value in "output" was empty string. I was just provided the following link from a colleague (which he says is the answers to my prayers) that I will try when I get home. http://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net – user3071434 Feb 19 '16 at 12:56
  • 1
    I found when using the Handbrake CLI that most output is written to stderr rather than stdout. If you use the `--json` option, you will still get the normal stderr output but JSON on stdout. – Joe Skeen Apr 01 '20 at 00:08