【问题标题】:Running linux bash command from cakephp从 cakephp 运行 linux bash 命令
【发布时间】:2014-02-19 14:18:56
【问题描述】:

现在我正在使用 CakePHP 开发一个项目,我想通过它运行一个 bash shell 脚本。我阅读了console and shells 上的文档,但无法将其与 bash shell 脚本链接。通过 cake php 的控制台在终端上的“./MyShellScript”或“ls -l”之类的东西足以运行 bash shell 脚本。或者,任何相同的插件!另外,如果有其他方法,那将很有帮助。

【问题讨论】:

    标签: php linux bash shell cakephp-2.0


    【解决方案1】:

    如果要打印 bashscript 的输出,请使用 system

    system ( string $command [, int &$return_var ] )
    

    如果没有,请使用exec

     exec( string $command [, array &$output [, int &$return_var ]] )
    

    【讨论】:

      【解决方案2】:

      在 php 中,您可以使用 exec() 函数执行任何 bash 命令:

      exec("sh myBashScript.sh",$output);
      

      只需确保您的 apache 用户具有执行该文件所需的权限。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-09
        • 2018-02-16
        • 2020-07-06
        相关资源
        最近更新 更多