How to catch command prompt errors in asp.net code?
I am running ffmpeg.exe from command prompt through asp.net code.
Is there any method to know success and errors of the ffmpeg.exe execution in asp.net code ?
My code is as follows:
string OutputFile, FilArgs;
//output file format in swf
//outputfile = SavePath + "SWF\\" + withoutext + ".swf";
OutputFile = SavePath + "SWF\\" + WithOutExt + ".flv";
//file orguments for FFMEPG
//filargs = "-i \"" + inputfile + "\" -ar 22050 \"" + outputfile;
FilArgs = "-开发者_运维技巧i \"" + InputFile + "\" -ar 22050 \"" + OutputFile;
//string spath;
//spath = Server.MapPath(".");
Process proc;
proc = new Process();
proc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
proc.StartInfo.Arguments = FilArgs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = false;
try
{
proc.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
proc.WaitForExit();
proc.Close();
Any one please help me to sort this out?
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
stdout = p.StandardOutput.ReadToEnd();
stderr = p.StandardError.ReadToEnd();
Those statements generates outputs that you needed.
personally i'd rewrite the code similar to as follows:
Process proc = new Process();
try
{
proc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
proc.StartInfo.Arguments = FilArgs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
proc.WaitForExit();
proc.Close();
}
and that may give you a better way to deal with errors - the way your code was if there was an exception then the process would not close.
精彩评论