in reply to cd pwd dir chdir version default directory

Is it possible that the odd-ball machine2 happens to have some unexpected difference in the shell configuration that is used to run the perl script? If so, this would extend to the environment used to run a "cd" command via backticks (in a subshell). For example, it may be that a subshell "cd" command runs a different .exe file compared to what the other machines are doing. (Just a guess)

In particular, a unix-like "cd" command would actually change the current working directory to the "home" directory for the shell, rather than reporting the current shell directory path.

  • Comment on Re: cd pwd dir chdir version default directory

Replies are listed 'Best First'.
Re^2: cd pwd dir chdir version default directory
by blc3355447 (Novice) on Dec 04, 2007 at 00:58 UTC
    Exactly. I think I could make a pretty good living off of your guesses. I am too embarrassed to mention how much time I spent on this. Yes, in "hkey_current_user\software\microsoft\command processor" you can add a dword called "autorun" and basically issue any command you want. On machine2, it had "cd \". After deleting that entry in resedit, the script works find. Thank you very much. BLC

      Yes, this is a chronic nuisance when writing portable Perl scripts under Windows. Because our scripts run on many different customer machines, we don't have the option of removing the autorun value from the Registry. There are two ways around this:

      • Use CMD /D to disable autorun; for example, print "\ncd=" . `cmd /d/c cd`; in your example program.
      • Contrive to execute the command without invoking a shell; for example, system { $exe } @args, where $exe is the executable name and @args are its arguments (see perldoc -f exec for more details). Though more work, this approach leads to programs that are more robust and a bit more efficient, in that no shell process is created.

        Contrive to execute the command without invoking a shell; for example, system { $exe } @args, where $exe is the executable name and @args are its arguments (see perldoc -f exec for more details).

        Just wanted to point out an aside, that for the "cd" command, the shell is the command interpreter. It's a built-in in most shells, CMD.EXE or bash or otherwise. There are other built-ins that apply to this pattern as well.

        Running a subprocess to change directories won't help the shell or other parent processes, of course, as the child's process is insular. To change directories in perl, also use the builtin (the chdir function).

        --
        [ e d @ h a l l e y . c c ]