Search code examples
perlbackticks

perl backticks not working for cd. Why?


I'm using AS perl on win7.

print `cd \\\\ `; # does nothing, says nothing

Same with qx()

print `dir \\\\ `;  # correctly prints the root directory

other commands also seem to work fine.

cd works fine from the command line of a batch file.

Has anyone else seen this? Is there a workaround?


Solution

  • You may be looking for chdir. Using a shell command in backticks is not going to have a lasting effect. When you run a backtick command, you spawn a new shell, execute the command, and return the standard output to Perl. Then the shell exits and any and all changes to it is lost.