I need my perl program to execute a DIR command in the windows command line. I use these lines:
$percorso1= C:\PerlEsercitazione\FileCompare1\VSS\Divina Cömmediä\ProgettoTest
my $cmd_string = "dir /ad /b ".$percorso1 ;
my @result = qx {$cmd_string};
obviously $percorso1
is the path to follow. The problem is that @result
turns out to be empty. I typed the DIR command directly in the shell and it works, so the problem should be in the qx function. Where am I wrong?
anyway I tried using readdir ,opendir and closedir but using this code:
opendir ("Temp_VSS", $percorso1);
my @result = readdir ($percorso1);
closedir ("Temp_VSS");
and I get the error "bad symble for dirhandle"
Not sure why does this fail (could be that dir is not really an executable but rather a shell command so you could try with
cmd /c "dir /ad /b $percorso1"
). But generally it's better to avoid external programs for something you have internal functions.Here specifically File::Slurp::read_dir can do the same for you much easier and with internal error handling: