For tools that don't follow that general rule, you could use $ENV{PATH} to see if a file with a chosen name happens to exist in any of the user's current execution-path directories -- something like:
(updated to include the "tool_path" variable and the "die" statement)my $tool_name = "tar"; # simple example my $tool_path = ''; for my $path ( split /:/, $ENV{PATH} ) { if ( -f "$path/$tool_name" && -x _ ) { print "$tool_name found in $path\n"; $tool_path = "$path/$tool_name"; last; } } die "No $tool_name command available\n" unless ( $tool_path );
I don't know, but you might need to split /[;:]/ if you want that to work in the "standard" windows shell as well as on unix(-like) systems.
If you promise to only use a unix-like environment (incl, cygwin or uwin on windows), you could also depend on the "which" command:
my $tool_name = "tar"; my $tool_path = `which $tool_name`; die "No $tool_name command available\n" unless ( $tool_path );
(Another update: D'oh -- I should have known there was a module for this!)
In reply to Re: How to find whether an external commands exists
by graff
in thread How to find whether an external commands exists
by sathiya.sw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |