简体   繁体   English

如何在PHP中执行命令行实用程序?

[英]How to execute command-line utilities in PHP?

I have very limited knowledge when it comes to console commands. 关于控制台命令,我的知识非常有限。 What I'm trying to achieve is to execute a console command within a PHP query. 我想要实现的是在PHP查询中执行控制台命令。

Example

<?php 

   $sql = mysql_query("SELECT * FROM `users`");
   while( $select_users = mysql_fetch_array( $sql )){

   } 

?>

The command I want to execute within the WHILE 我想在WHILE中执行的命令

So within this query I want to execute this command however am unsure how to achieve this; 因此,在此查询中,我想执行此命令,但是不确定如何实现。 I have looked at similar questions however unsure how to implement them into my example. 我已经看过类似的问题,但是不确定如何在我的示例中实现它们。

ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 \
   -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg

You can use exec function of php like this 您可以像这样使用php的exec函数

$command = 'ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg';

exec($command);

In additional to exec you can use from following command: 除了exec以外,您还可以从以下命令使用:

$output = shell_exec($command);

This command execute command via shell and return the complete output as a string, more information: http://php.net/manual/en/function.shell-exec.php 此命令通过shell执行命令,并以字符串形式返回完整的输出,更多信息: http : //php.net/manual/zh/function.shell-exec.php

I had same requirement like you and used from this command 我和您一样有相同的要求,并在此命令中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM