PHP shell scripting problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
MathewByrne
Forum Commoner
Posts: 38
Joined: Sat Mar 27, 2004 9:49 pm
Location: Australia

PHP shell scripting problem

Post by MathewByrne »

I'm trying to implement a quick php shell script which will take me to a specified directory. This doesn't work however:

Code: Select all

...
exec("cd " . $path);
...
In fact nothing happens inside bash. Is this a limitation of scripting in PHP?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: PHP shell scripting problem

Post by Chris Corbyn »

MathewByrne wrote:I'm trying to implement a quick php shell script which will take me to a specified directory. This doesn't work however:

Code: Select all

...
exec("cd " . $path);
...
In fact nothing happens inside bash. Is this a limitation of scripting in PHP?
Nope. PHP does change it's working directory.... but that's only local to the script... it won't effect your bash environment.

You could possibly try this but it'll no doubt have the same result:

Code: Select all

`export PWD=/somewhere/`;
User avatar
MathewByrne
Forum Commoner
Posts: 38
Joined: Sat Mar 27, 2004 9:49 pm
Location: Australia

Post by MathewByrne »

Yeah I noticed calling getcwd(); had changed. Hmm... might have to actually write a shell script for once... Anyone have a better solution?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

MathewByrne wrote:Yeah I noticed calling getcwd(); had changed. Hmm... might have to actually write a shell script for once... Anyone have a better solution?
Even BASH scipts do the same thing. I'm not sure what the solution is but it must be very simple... I've tried and failed in the past too.
User avatar
MathewByrne
Forum Commoner
Posts: 38
Joined: Sat Mar 27, 2004 9:49 pm
Location: Australia

Post by MathewByrne »

Ah well, I'll make do with a buch of alias ___='cd ...___' for now :(
dubbelpunt
Forum Newbie
Posts: 3
Joined: Thu Mar 09, 2006 8:01 am

Post by dubbelpunt »

if you need to change your directory, you can use the function chdir().
Post Reply