Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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";


Comment on Re: unable to change remote directory
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://326717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-07-10 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls