从.NET C#

问题描述:

调用Mp4Box.exe你好,我想提出一个代码,以便在使用mp4box.exe从.NET C#

我想执行这个命令行mp4视频做一些编辑:

"D:\Work\Me\CloudContentUpload\trunk\ContentUploading Current\bin\Debug\Mp4Box\Mp4Box.exe" -isma -inter 500 "C:\Users\Abdullah\Desktop\videoo\amr khaled - Asmaa_elmogeb\Asmaa_elmogeb(1).mp4" 

该命令执行成功当我在命令行

手动运行它,但我尝试用下面的C#代码来执行它:

public string ExecuteCommandSync(object command) 
    { 
     try 
     { 
      // create the ProcessStartInfo using "cmd" as the program to be run, 
      // and "/c " as the parameters. 
      // Incidentally, /c tells cmd that we want it to execute the command that follows, 
      // and then exit. 
      System.Diagnostics.ProcessStartInfo procStartInfo = 
       new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command); 

      // The following commands are needed to redirect the standard output. 
      // This means that it will be redirected to the Process.StandardOutput StreamReader. 
      procStartInfo.RedirectStandardOutput = true; 
      procStartInfo.UseShellExecute = false; 
      // Do not create the black window. 
      procStartInfo.CreateNoWindow = true; 
      // Now we create a process, assign its ProcessStartInfo and start it 
      System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
      proc.StartInfo = procStartInfo; 

      proc.Start(); 
      // Get the output into a string 
      string result = proc.StandardOutput.ReadToEnd(); 
      // Display the command output. 
      return result; 
     } 
     catch (Exception objException) 
     { 
      return objException.Message; 
     } 
    } 

返回的结果是空字符串!

你不需要为此调用cmd。

您应该直接调用您的程序,并将参数传递给的Arguments属性。

+0

非常感谢您的帮助..成功地工作 – 2012-04-25 13:15:11