在exec函数中如何知道命令中的错误? [英] How can I know the error in command in an exec function?

查看:307
本文介绍了在exec函数中如何知道命令中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ffmpeg命令在php中剪切带有exec功能的视频。但它不是创建一个视频文件,并没有显示任何错误。我使用exec如下

  exec(ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00 :10.0 -acodec copy -vcodec copy -async 1 output.flv); 

我可以获得任何帮助,以了解这里发生的错误是什么?

  exec(ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output FLV的,$输出); 

我也试过了。但是我没有在变量 $ output 中获取任何错误信息

解决方案

作为一般规则,您首先需要检查返回值:非零值表示存在错误(假定您正在运行的程序的作者遵守标准)。此值在 exec()的第三个参数中捕获。 p>

其次,许多程序不会向标准输出发送错误消息。而是使用标准错误。在这种情况下,将重定向后者似乎安全前者:

  exec(ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv 2>& 1,$ output,$ return_value); 


I am using a ffmpeg command to cut a video with exec function in php. But it is not creating a video file and doesn't show any errors. I used exec as below

exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv");

Can I get any help to know what is the error happening here?

exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv",$output);

I tried it also. But I didn't get any error message in variable $output

解决方案

As a general rule, you first need to check the return value: non-zero values indicate there has been an error (given that the author of the program you are running adheres to the standard). This value is captured in exec()'s third argument.

In second place, many programs do not send error messages to the standard output. Instead, they use the standard error. In this case, it seems safe to just redirect the latter to the former:

exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv 2>&1", $output, $return_value);

这篇关于在exec函数中如何知道命令中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆