gpt4 book ai didi

php - 将多行 linux 发送到 PHP exec()

转载 作者:太空狗 更新时间:2023-10-29 12:04:27 30 4
gpt4 key购买 nike

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

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

这是怎么回事?

最佳答案

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

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

关于php - 将多行 linux 发送到 PHP exec(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205182/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com