Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: unable to change remote directory

by markov (Scribe)
on Feb 05, 2004 at 07:44 UTC ( #326717=note: print w/replies, xml ) Need Help??

in reply to unable to change remote directory

On UNIX systems, all processes are nicely separated from each other. Changes made in one process do not affect any other (without help of the kernel)

Only when a new process starts, the child get some info, for instance the current directory, the user id and environment variables. But from then on, the child is a different process.

Well, when you call system() or qx() --backticks, you start shell which handles your cd. That shell is done by a child process, which itself may change the directory nicely, but, by reason of full process separation, will not affect the current location of its parent.

For the same reason, 'cd' is a shell built-in: the shell cannot let some other process do it's job. The same for ftp: you cannot do !cd, but need lcd to change the local working directory. There is no /bin/cd !

So: `cd $a` or qx(cd $a) is not working because a sub-shell moves. system("cd", $d) doesn't use a shell, but cannot work because there is no /bin/cd.

Finally, chdir is the Perl built-in, which should work given that the directory exists. But of course, you may not be permitted to access the directory you want to go to. Therefore, try

use Cwd; print "From: ",getcwd(), "\n"; chdir $d or die "To $d: $!\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://326717]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-05-25 11:44 GMT
Find Nodes?
    Voting Booth?