c#调用EXE文件方法
2010-11-19 09:53 zhaoyang 阅读(956) 评论(0) 编辑 收藏 举报 static void ExcuteProcess(string exe, string arg, DataReceivedEventHandler output)
{
using (var p = new Process())
{
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = arg;
p.StartInfo.UseShellExecute = false; //输出信息重定向
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += output;
p.ErrorDataReceived += output;
p.Start(); //启动线程
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit(); //等待进程结束
}
}
调用
ExcuteProcess("ffmpeg.exe", "-y -i 1.flv 1.mp3", (s, e) => Console.WriteLine(e.Data));