in reply to Re: trouble with a simple script
in thread problem running executable in subdirectories
You need to undo the chdir since you are using paths relative to the original directory.
Here's a convenient way of doing that:
use File::chdir qw( $CWD ); use File::Slurp qw( read_dir ); my @dirs = grep -d, read_dir('.'); for (@dirs) { local $CWD = $_; system '/somepath/foo.exe'; }
Or since we know we're just going one level down,
use File::Slurp qw( read_dir ); my @dirs = grep -d, read_dir('.'); for (@dirs) { chdir $_ or die; system '/somepath/foo.exe'; chdir '..' or die; }
Another way is to make the paths absolute.
Update: Added alternative.
|
|---|