PHP detect if shell_exec() command failed

会有一股神秘感。 提交于 2019-11-30 17:18:43

问题


I'm running the ffmpeg command within PHP's shell_exec() to convert several videos in a list. Is there anyway to detect if an error happened while the video was being converted (or atleast verify it fully completed the conversion)?

I don't want to stop converting other videos if an error happens, just the ability to record the error.

<?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)
    }
?>

回答1:


Capture the exit code with another system call function like exec:

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

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

Any decent utility will exit with a code other than 0 on error.




回答2:


$return=shell_exec('ffmpeg ...');

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

}


来源:https://stackoverflow.com/questions/7923876/php-detect-if-shell-exec-command-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!