【问题标题】:PHP detect if shell_exec() command failedPHP 检测 shell_exec() 命令是否失败
【发布时间】:2011-10-28 00:09:48
【问题描述】:

我在 PHP 的 shell_exec() 中运行 ffmpeg 命令来转换列表中的多个视频。是否有办法检测在转换视频时是否发生错误(或至少验证它完全完成了转换)?

如果发生错误,我不想停止转换其他视频,只是能够记录错误。

<?php
    shell_exec('ffmpeg -i downloads/flv/file1.flv -vcodec libvpx -acodec libvorbis downloads/webm/file1.webm');

    if(error) {
     //run a command here to report the error (ie. MySQL or email)
    }
?>

【问题讨论】:

  • 您是否在寻找从 ffmpeg 返回的错误?
  • shell_exec 返回执行命令的输出,如果 ffmpeg 打印错误你应该能够解析它。
  • 如何获取ffmpeg返回的错误?

标签: php ffmpeg shell-exec


【解决方案1】:

使用另一个系统调用函数(如exec)捕获退出代码:

exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}

任何体面的实用程序都会在出错时退出,并返回 0 以外的代码。

【讨论】:

  • 或者检查是否 ($return != 1)。 1 是错误,0 是没有错误退出代码。您可以直接在 Unix CLI 中使用 echo "$?" 进行调试。执行你的命令后。
  • 嗯,0 表示“全绿”,而 0 以外的任何内容 表示“错误”。除了1,还有更多错误代码。我不知道ffmpeg 是否特别使用除了01 之外的任何东西。
【解决方案2】:
$return=shell_exec('ffmpeg ...');

if ($return) { //look at what it returns do what you will with the data

}

【讨论】:

    猜你喜欢
    • 2017-02-09
    • 2014-12-29
    • 1970-01-01
    • 2014-05-30
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    相关资源
    最近更新 更多