I have code like below
var psi = new ProcessStartInfo
{
FileName = "ffmpeg.exe",
Arguments = "-i " + fName + " -s " + Width + "x" + Height + " " + fName.Substring(0, fName.Length - 4) + "_.mp4",
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
var p = Process.Start(psi);
p.BeginErrorReadLine();
p.BeginOutputReadLine();
string fNamestderr = fName.Substring(0, fName.Length - 4) + "(stderr).txt";
string fNamestdout = fName.Substring(0, fName.Length - 4) + "(stdout).txt";
StreamWriter stdin = p.StandardInput;
//stdin.WriteLine(["Command Text"]);
p.OutputDataReceived += (s, evt) => {
if (evt.Data != null)
{
using (StreamWriter sw = File.AppendText(fNamestdout))
{
sw.WriteLine(evt.Data);
}
Console.WriteLine(evt.Data);
}
};
p.ErrorDataReceived += (s, evt) => {
if (evt.Data != null)
{
using (StreamWriter sw = File.AppendText(fNamestderr))
{
sw.WriteLine(evt.Data);
}
Console.WriteLine(evt.Data);
}
};
I am trying to read console and see it at the sime time on screen in console.
I do
p.BeginErrorReadLine();
p.BeginOutputReadLine();
to start reading console but it fails to appear on screen so I am doing
Console.WriteLine(evt.Data);
I still cannot see anything on console.
AND SECOND ISSUE IS THAT console throws error that file already exists and will be overwritten
BUT it does not seem to be redirected so I am not getting any notice of it.
1) How to do both reading console output and seeing it on console at the same time?
2) What about overriding file error? Why am I not getting any notice of it? How to get it?