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

In reply to Re: unable to change remote directory by markov
in thread unable to change remote directory by cryogenie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.