2012-04-25 46 views
0

調用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; 
     } 
    } 

返回的結果是空字符串!

回答

1

你不需要爲此調用cmd。

您應該直接調用您的程序,並將參數傳遞給的Arguments屬性。

+0

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