I'm trying to process multiple unix calls with exec()
but the first command seems to have no effect on the second:
exec('cd ../my/new/directory/');
echo exec('pwd')' //directory the PHP is in. not the new directory/
What's the deal here?
I'm trying to process multiple unix calls with exec()
but the first command seems to have no effect on the second:
exec('cd ../my/new/directory/');
echo exec('pwd')' //directory the PHP is in. not the new directory/
What's the deal here?
When you call PHP's exec()
, PHP will fork
a new process, and exec
(Unix syscall) the cd
command. The parent process (PHP) will then wait
on the child process to complete.
Thus, the cd
only takes effect in the child process. After cd
returns, your parent process (PHP) is in the same state it was in before.