in reply to Best way to change directories for a script?

There are multiple solutions to this. The absolute safest is to launch the command:
"perl", "-e", qq{chdir "/usr/bin"; exec @ARGV;}, $original_cmd, @args
Another cute one is to use my ReleaseAction. The following example is straight from the documentation:
use Carp; use Cwd; use ReleaseAction; sub cd_to { chdir($_[0]) or confess("Cannot chdir to $_[0]: $!"); } sub tmp_cd { my $cwd = cwd(); cd_to(shift); ReleaseAction->new(\&cd_to, $cwd); } sub something_interesting { my $in_dir = tmp_cd("some_dir"); # Do something interesting in the new dir # I will automagically return to the old dir # when I exit the subroutine and $in_dir goes # out of scope. }
Note that this is less safe than the previous solution because if someone renames or deletes your previous working dir, when you try to cd back you will fail (or worse yet will succeed in going to the wrong place). However that risk is miniscule, and when I had to write lots of batch jobs, it was a risk that I was generally willing to accept.