【发布时间】:2020-01-10 13:37:38
【问题描述】:
我必须在 asp.net 中使用 Process 运行两个命令,如下所示,第一个命令运行成功,而第二个命令在 result = p.StandardOutput.ReadToEnd() p>
如何实现这一点以成功运行这两个命令?
private static string FFMPEG_EXE_PATH = @"D:\ffmpeg\bin\ffmpeg.exe";
private static string FFPROBE_EXE_PATH = @"D:\ffmpeg\bin\ffprobe.exe";
protected void Page_Load(object sender, EventArgs e)
{
string firstArgs = @"-hide_banner -show_format -show_streams -pretty D:\Video\dolbycanyon.m4v";
var result1 = Execute(FFPROBE_EXE_PATH, firstArgs);
string secondArgs = @"-hide_banner -ss 00:00:05 -i D:\Video\dolbycanyon.m4v -r 1 -t 1 -f image2 D:\Video\test.jpg";
var result2 = Execute(FFMPEG_EXE_PATH, secondArgs);
}
private string Execute(string exePath, string parameters)
{
string result = String.Empty;
using (Process p = new Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = exePath;
p.StartInfo.Arguments = parameters;
p.Start();
result = p.StandardOutput.ReadToEnd(); // the application hung here for the second command
p.WaitForExit();
}
return result;
}
【问题讨论】:
-
您是否尝试过手动运行第二个命令以查看它为何挂起?
-
@Martin 是的,第二个命令在命令提示符下运行顺利。