Skip to content

Commit 4e4e803

Browse files
committed
Fix command existence checks without which
1 parent 6f6fa51 commit 4e4e803

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

lib/Rex/Interface/Exec/Base.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sub execute_line_based_operation {
5454
sub 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();

lib/Rex/Interface/Exec/Local.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ sub exec {
114114
sub 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
}

t/can_run.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Test::Warnings;
1111
use 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' );

0 commit comments

Comments
 (0)