PHP exec输出不返回并执行命令

时间:2015-10-04 15:20:21

标签: php windows cmd exec youtube-dl

我正在尝试在Windows Server机器上用PHP执行命令。

我使用的代码是:

<?php
$out = array();
exec('C:\libs\bin\youtube-dl -o "C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw"  "http://youtube.com/watch?v=SrMKY5Aoyrw"', $out);
print_r($out);
?>

我在PHP中的结果是:

Array
(
[0] => [youtube] SrMKY5Aoyrw: Downloading webpage
[1] => [youtube] SrMKY5Aoyrw: Downloading video info webpage
[2] => [youtube] SrMKY5Aoyrw: Extracting video information
[3] => [youtube] SrMKY5Aoyrw: Downloading DASH manifest
[4] => [youtube] SrMKY5Aoyrw: Downloading DASH manifest
)

我的结果应该是:

C:\xampp\htdocs\API\jbb15\convert>C:\libs\bin\youtube-dl -o "C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw" "http://youtube.com/watch?v=SrMKY5Aoyrw"
[youtube] SrMKY5Aoyrw: Downloading webpage
[youtube] SrMKY5Aoyrw: Downloading video info webpage
[youtube] SrMKY5Aoyrw: Extracting video information
[youtube] SrMKY5Aoyrw: Downloading DASH manifest
[youtube] SrMKY5Aoyrw: Downloading DASH manifest
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[download] Destination: C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw.f137
[download] 100% of 111.72MiB in 00:01
[download] Destination: C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw.f251
[download] 100% of 8.13MiB in 00:00
[ffmpeg] Merging formats into "C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw.mkv"
Deleting original file C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw.f137 (pass -k to keep)
Deleting original file C:\xampp\htdocs\API\jbb15\convert\SrMKY5Aoyrw.f251 (pass -k to keep)

这个问题是:如果将命令复制到Windows CMD中,与上述PHP脚本完全相同的命令可以正常工作。没有PHP错误日志。命令--verbose将在PHP中不返回任何内容,但在windows cmd中起作用。

1 个答案:

答案 0 :(得分:0)

感谢您的贡献。问题是我没有设置> msg.log 2> msg2.log

WARNING: Requested formats are incompatible for merge and will be merged into mkv.2>中运行,因此停止了执行。

命令--no-warnings也可能已经解决了。