cryogenie has asked for the wisdom of the Perl Monks concerning the following question:

i m trying to write a daemon tha executes certain process on data staored at different locations.......i m able to connect to my daemon and pass the required info...but ther is a change directory involved which the forked process is unable to execute
i ve tried
chdir "$d"; system("cd","$d"); @a=`cd $a`;
pl help

Replies are listed 'Best First'.
Re: unable to change remote directory
by markov (Scribe) on Feb 05, 2004 at 07:44 UTC

    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";
Re: unable to change remote directory
by eyepopslikeamosquito (Archbishop) on Feb 05, 2004 at 07:09 UTC

    When you try say:

    chdir($d) or die "error: cd '$d' failed: $!";

    What does $! tell you is the matter?

Re: unable to change remote directory
by parkprimus (Sexton) on Feb 05, 2004 at 16:18 UTC
    How are you connected to this remote server? Telnet? FTP?