为什么此方法不重定向 .exe [ffmpeg] 的输出?
我有方法:
public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit)
{
string retMessage = "";
using (Process p = new Process())
{
p.StartInfo.FileName = exePathArg;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.Arguments = argumentsArg;
p.StartInfo.UseShellExecute = false;
try
{
p.Start();
StreamReader myOutput = p.StandardOutput;
retMessage = "STANDARD OUTPUT: " + myOutput.ReadToEnd();
p.WaitForExit(timeToWaitForProcessToExit);
}
catch (Exception ex)
{
retMessage = "EXCEPTION THROWN: " + ex.ToString();
}
finally
{
try
{
p.Kill();
}
catch { }
}
}
return retMessage;
}
但它不会将我的输出重定向到 retMessage。有人有什么想法吗?我测试了bat文件中的参数,输出肯定是输出。
干杯, 皮特
I have the method:
public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit)
{
string retMessage = "";
using (Process p = new Process())
{
p.StartInfo.FileName = exePathArg;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.Arguments = argumentsArg;
p.StartInfo.UseShellExecute = false;
try
{
p.Start();
StreamReader myOutput = p.StandardOutput;
retMessage = "STANDARD OUTPUT: " + myOutput.ReadToEnd();
p.WaitForExit(timeToWaitForProcessToExit);
}
catch (Exception ex)
{
retMessage = "EXCEPTION THROWN: " + ex.ToString();
}
finally
{
try
{
p.Kill();
}
catch { }
}
}
return retMessage;
}
But it doesnt redirect my output to retMessage. Anyone any ideas? I tested the arguments in a bat file and output is definitely output.
Cheers,
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测(同意dtb的评论):
AFAIK ffmpeg 使用 stdout 来输出二进制数据(多媒体、快照等),而 stderr 用于记录目的。在您的示例中,您使用标准输出。
因此,将代码更改为:
它应该可以解决您的问题。
My guess (agree with dtb's comment):
AFAIK
ffmpeg
uses stdout to pipe out binary data(multimedia, snapshots, etc.) and stderr is used for logging purposes. In your example you use stdout.So, change you code to:
and it should solve your problem.