in reply to Changing directory in cmd window

Each process has its own work directory. Changing the work directory of one of its children (chdir("\\newdir")) or one of its grandchildren (system("cd \\newdir")) will have no effect on the work directory of the shell.

One solution it to output a directive to the shell and have the shell interpret that directive:

>cd C:\ >for /f usebackq %q in (`perl -e"print 'foo'"`) do cd %q >cd C:\foo

(Change %q to %%q in a batch file)