Reputation: 85
my $exe = "'C:/Program Files/Common Files/executable.exe'";
if(! -X $exe) {
print "exe file not found";
exit 3;
}
my $cmd = $exe.' status';
@lines = qx ( $cmd );
My problem is that I can execute this command just fine, but I cannot for the life of me figure out how to check for the existence of the exe-file. Any hints? I have tried different sorts of quotation marks, -f, -X, -e ... nothing works! Any help is much appreciated.
Upvotes: 0
Views: 1171
Reputation: 126722
The -f
operator would work fine, except that you have superfluous quotation marks in your filename.
Of course all that -f
tells you on Windows is that the file exists and isn't a directory, but presumably that is all that you need.
Additional double quotes do need to be put in the command line around the executable file's name if the path contains whitespace, but it's best to do that at the point you need them and no earlier. Try this:
my $exe = 'C:/Program Files/Common Files/executable.exe';
unless (-f $exe) {
print "exe file not found";
exit 3;
}
my $cmd = qq("$exe" status);
my @lines = qx($cmd);
Upvotes: 3