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

I've tried the command: system "cd /d c:\MyNewWorkingDir"; But that doesn't change my working dir. Anyone that can give me some advices? Regards Sten
  • Comment on Windows NT: How Do I change Working/Current directory within a perl script,

Replies are listed 'Best First'.
Re: Windows NT: How Do I change Working/Current directory within a perl script,
by valdez (Monsignor) on Mar 22, 2003 at 14:48 UTC

    Accordingly to perldoc -f system:

    Does exactly the same thing as "exec LIST", except that a fork is done first, and the parent process waits for the child process to complete.

    This means that only the forked process will change its working directory; you should use instead the command chdir.

    HTH, Valerio

Re: Windows NT: How Do I change Working/Current directory within a perl script,
by Mr. Muskrat (Canon) on Mar 22, 2003 at 14:48 UTC
Re: Windows NT: How Do I change Working/Current directory within a perl script,
by Anonymous Monk on Mar 22, 2003 at 14:44 UTC
Re: Windows NT: How Do I change Working/Current directory within a perl script,
by Nkuvu (Priest) on Mar 22, 2003 at 14:51 UTC

    chdir works, and I'd suggest that as well. But there's also the problem in your system call of backslashes and quotes. Specifically, you need to do one of three things -- change the quoted stuff to "cd /d c:\\MyNewWorkingDir" or 'cd /d c:\MyNewWorkingDir' (note the single quotes) or "cd /d c:/MyNewWorkingDir"

    Note that I don't think this will solve your problems, as noted in other replies. But any other system calls will need to have the \ working properly...