我試圖處理多個UNIX與exec()
要求,但第一個命令似乎對第二個產生影響:發送多個Linux行PHP的exec()
exec('cd ../my/new/directory/');
echo exec('pwd')' //directory the PHP is in. not the new directory/
這是怎麼回事嗎?
我試圖處理多個UNIX與exec()
要求,但第一個命令似乎對第二個產生影響:發送多個Linux行PHP的exec()
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)然後將子進程的wait
完成。
因此,cd
只在子進程中生效。在cd
返回後,您的父進程(PHP)處於與之前相同的狀態。
合併然後與';'分開定義語句的結尾 $ x = shell_exec('cd ../my/new/directory/;pwd'); echo $ x;