Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PHP执行linux程序?_Php_Linux_Exec - Fatal编程技术网

如何从PHP执行linux程序?

如何从PHP执行linux程序?,php,linux,exec,Php,Linux,Exec,我想从php执行一个linux程序,我该怎么做 在linux终端中,我通常执行以下操作: ./program_name -o argument1 -f argument2 -out argument3 在PHP中如何实现这一点?您尝试过exec吗?壳牌执行董事?系统 您还应该了解如何转义特殊字符。 您还必须确保运行php/apache等的Linux用户具有运行系统命令所需的权限 检查功能 <?php $output = shell_exec('/path/to/program_na

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

在linux终端中,我通常执行以下操作:

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

在PHP中如何实现这一点?

您尝试过exec吗?壳牌执行董事?系统

您还应该了解如何转义特殊字符。 您还必须确保运行php/apache等的Linux用户具有运行系统命令所需的权限

检查功能

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

对我试过了,但似乎什么也没发生。我对如何传递参数感到困惑。php的工作目录不同于linux程序所在的目录,而是程序的完整路径。检查系统错误日志,看看有什么问题。为什么不能简单地执行“/path/to/program/-o argument1-f argument2-out argument3”;?