擅长:python、mysql、java
<p>你问题中的这个例子对我很有用:</p>
<pre><code><?php
$command = escapeshellcmd('youtube-dl https://www.youtube.co/watch?v=z456k6yBeo0');
$output = shell_exec($command);
echo $output;
</code></pre>
<p>你的PHP版本是什么?我的是5.5.9。在</p>
<p>您也可以像这样使用proc\u open(我们可能在这里遗漏了错误,所以请尝试更新版本):</p>
^{pr2}$
<p>您还可以使用exec,它将显示退出状态:</p>
<pre><code><?php
$cmd = 'youtube-dl https://www.youtube.co/watch?v=z456k6yBeo0';
exec(escapeshellcmd($cmd), $output, $status);
if ($status) echo "Exec command failed.";
else echo var_dump($output);
</code></pre>