0

您好,我正在编写代码以使用 mp4box.exe 对 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;
        }
    }

返回的结果是空字符串!!

4

1 回答 1

1

您不需要为此调用 cmd 。

您应该直接调用您的程序并将参数传递ArgumentsProcessStartInfo.

于 2012-04-25T13:02:18.630 回答