Search code examples
phpwindowscmdexecyoutube-dl

PHP exec output does not return and execute commands


I am trying to execute a command in PHP on a Windows Server Machine.

The code i am using is:

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

My result in PHP is:

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
)

My result should be:

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)

The problem about this is: The exact same command as in the above PHP script works perfectly if the command is copied into the Windows CMD. There are no PHP error logs. The command --verbose will return nothing in PHP, but works in windows cmd.


Solution

  • Thanks for contributing. The problem was that i did not set > msg.log 2> msg2.log.

    The line WARNING: Requested formats are incompatible for merge and will be merged into mkv. was run in 2> and therefore stopped the execution.

    The command --no-warnings might have solved it too.