Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Revision history for Rex
- Prefer GNU tools on Solaris
- Fix parsing FreeBSD memory details
- Recognize laundry memory on FreeBSD
- Fix command existence checks without which

[DOCUMENTATION]

Expand Down
2 changes: 1 addition & 1 deletion lib/Rex/Interface/Exec/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sub execute_line_based_operation {
sub can_run {
my ( $self, $commands_to_check, $check_with_command ) = @_;

$check_with_command ||= "which";
$check_with_command ||= "command -v";

my $exec = Rex::Interface::Exec->create;
my $cache = Rex::get_cache();
Expand Down
2 changes: 1 addition & 1 deletion lib/Rex/Interface/Exec/Local.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ sub exec {
sub can_run {
my ( $self, $commands_to_check, $check_with_command ) = @_;

$check_with_command ||= $^O =~ /^MSWin/i ? 'where' : 'which';
$check_with_command ||= $^O =~ /^MSWin/i ? 'where' : 'command -v';

return $self->SUPER::can_run( $commands_to_check, $check_with_command );
}
Expand Down
6 changes: 3 additions & 3 deletions t/can_run.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Test::Warnings;
use Rex::Commands::Run;

{
my $command_to_check = $^O =~ /^MSWin/ ? 'where' : 'which';
my $command_to_check = $^O =~ /^MSWin/ ? 'where' : 'sh';
my $result = can_run($command_to_check);
ok( $result, 'Found checker command' );
}
Expand All @@ -23,14 +23,14 @@ use Rex::Commands::Run;
}

{
my @commands_to_check = $^O =~ /^MSWin/ ? 'where' : 'which';
my @commands_to_check = $^O =~ /^MSWin/ ? 'where' : 'sh';
push @commands_to_check, 'non-existing command';
my $result = can_run(@commands_to_check);
ok( $result, 'Multiple commands - existing first' );
}

{
my @commands_to_check = $^O =~ /^MSWin/ ? 'where' : 'which';
my @commands_to_check = $^O =~ /^MSWin/ ? 'where' : 'sh';
unshift @commands_to_check, 'non-existing command';
my $result = can_run(@commands_to_check);
ok( $result, 'Multiple commands - non-existing first' );
Expand Down