当前位置:编程学习 > C#/ASP.NET >>

用C#调用CMD.exe

有谁能解释下下面的代码吗??

用C#调用CMD.exe,执行DOS命令 :

   Process p = new Process();
   p.StartInfo.FileName = "cmd.exe";
   p.StartInfo.UseShellExecute = false;
   p.StartInfo.RedirectStandardInput = true;
   p.StartInfo.RedirectStandardOutput = true;
   p.StartInfo.RedirectStandardError = true;
   p.StartInfo.CreateNoWindow = true;
   p.Start();
   string strOutput=null;
//   p.StandardInput.WriteLine("cd D:\\flv\\mplayer");
//   p.StandardInput.WriteLine("cd d:");
   p.StandardInput.WriteLine(string.Format("D:\\flv\\mplayer\\mencoder \"c:\\vs.wmv\" -o \"c:\\output.flv\" -of lavf  -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate={0}:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4:cmp=6:vb_strategy=1 -vf scale=512:-3 -ofps 12 -srate 22050",200));
   
   p.StandardInput.WriteLine("exit");
   strOutput = p.StandardOutput.ReadToEnd();
   Console.WriteLine(strOutput);
   p.WaitForExit();
   p.Close();

--------------------编程问答-------------------- 利用process启动一个命令行程序
程序是mencoder,一个flv的压缩器
作用是把文件c:\\vs.wmv 转换成 flv格式保存在 c:\\output.flv --------------------编程问答-------------------- 用MSDN,查询Process类的各种方法和属性,一目了然了。 --------------------编程问答-------------------- DllImport --------------------编程问答-------------------- MARK --------------------编程问答--------------------
引用楼主 baby01517 的回复:
有谁能解释下下面的代码吗??

用C#调用CMD.exe,执行DOS命令 :

  Process p = new Process();
  p.StartInfo.FileName = "cmd.exe";
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardInput = true;
  p.……


UP --------------------编程问答--------------------
引用 1 楼 skep99 的回复:
利用process启动一个命令行程序
程序是mencoder,一个flv的压缩器
作用是把文件c:\\vs.wmv 转换成 flv格式保存在 c:\\output.flv


up
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,