【问题标题】:sending multiple lines of linux to PHP exec()向 PHP exec() 发送多行 linux
【发布时间】:2013-12-10 21:27:16
【问题描述】:

我正在尝试使用 exec() 处理多个 unix 调用,但第一个命令似乎对第二个没有影响:

exec('cd ../my/new/directory/');
echo exec('pwd')' //directory the PHP is in. not the new directory/

这是怎么回事?

【问题讨论】:

    标签: php linux unix command-line


    【解决方案1】:

    当您调用 PHP 的 exec() 时,PHP 将 fork 一个新进程,并且 exec(Unix 系统调用)cd 命令。父进程(PHP)然后将wait对子进程完成。

    因此,cd只在子进程中生效cd 返回后,您的父进程 (PHP) 处于与之前相同的状态。

    【讨论】:

      【解决方案2】:

      然后组合并用';'分隔定义语句的结尾 $x = shell_exec('cd ../my/new/directory/;pwd'); 回声 $x;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-08
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多