如何从 PHP 执行 linux 程序?

How to execute linux program from PHP?

我想从 php 执行一个 linux 程序,我该怎么做?

在linux终端中,我通常这样做:

./program_name -o argument1 -f argument2 -out argument3

我如何在 PHP 中做到这一点?

你试过 exec() 了吗? shell_exec() ?系统()?
http://php.net/manual/en/function.system.php

您还应该看看 http://php.net/manual/en/function.escapeshellcmd.php 关于转义特殊字符的内容。
您还必须确保 Linux 用户 运行ning php/apache 等拥有 运行 系统命令所需的权限。

检查shell_exec()函数。

<?php
  $output = shell_exec('/path/to/program_name -o argument1 -f argument2 -out argument3');
  echo $output;
?>