File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Revision history for Rex
1111 - Prefer GNU tools on Solaris
1212 - Fix parsing FreeBSD memory details
1313 - Recognize laundry memory on FreeBSD
14+ - Fix command existence checks without which
1415
1516 [DOCUMENTATION]
1617
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ sub execute_line_based_operation {
5454sub can_run {
5555 my ( $self , $commands_to_check , $check_with_command ) = @_ ;
5656
57- $check_with_command ||= " which " ;
57+ $check_with_command ||= " command -v " ;
5858
5959 my $exec = Rex::Interface::Exec-> create;
6060 my $cache = Rex::get_cache();
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ sub exec {
114114sub can_run {
115115 my ( $self , $commands_to_check , $check_with_command ) = @_ ;
116116
117- $check_with_command ||= $^O =~ / ^MSWin/i ? ' where' : ' which ' ;
117+ $check_with_command ||= $^O =~ / ^MSWin/i ? ' where' : ' command -v ' ;
118118
119119 return $self -> SUPER::can_run( $commands_to_check , $check_with_command );
120120}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use Test::Warnings;
1111use Rex::Commands::Run;
1212
1313{
14- my $command_to_check = $^O =~ / ^MSWin/ ? ' where' : ' which ' ;
14+ my $command_to_check = $^O =~ / ^MSWin/ ? ' where' : ' sh ' ;
1515 my $result = can_run($command_to_check );
1616 ok( $result , ' Found checker command' );
1717}
@@ -23,14 +23,14 @@ use Rex::Commands::Run;
2323}
2424
2525{
26- my @commands_to_check = $^O =~ / ^MSWin/ ? ' where' : ' which ' ;
26+ my @commands_to_check = $^O =~ / ^MSWin/ ? ' where' : ' sh ' ;
2727 push @commands_to_check , ' non-existing command' ;
2828 my $result = can_run(@commands_to_check );
2929 ok( $result , ' Multiple commands - existing first' );
3030}
3131
3232{
33- my @commands_to_check = $^O =~ / ^MSWin/ ? ' where' : ' which ' ;
33+ my @commands_to_check = $^O =~ / ^MSWin/ ? ' where' : ' sh ' ;
3434 unshift @commands_to_check , ' non-existing command' ;
3535 my $result = can_run(@commands_to_check );
3636 ok( $result , ' Multiple commands - non-existing first' );
You can’t perform that action at this time.
0 commit comments