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 @@ -8,6 +8,7 @@ Revision history for Rex
[DOCUMENTATION]

[ENHANCEMENTS]
- Quote command arguments on Windows

[MAJOR]

Expand Down
6 changes: 5 additions & 1 deletion lib/Rex/Commands/Run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use Rex::Helper::SSH2::Expect;
use Rex::Config;
use Rex::Interface::Exec;
use Rex::Interface::Fs;
use English qw(-no_match_vars);

BEGIN {
if ( $^O !~ m/^MSWin/ ) {
Expand Down Expand Up @@ -297,7 +298,10 @@ sub run {
my $exec = Rex::Interface::Exec->create;

if ( $args && ref($args) eq "ARRAY" ) {
my $quoter = Net::OpenSSH::ShellQuoter->quoter( $exec->shell->name );
my $shell =
Rex::is_local() && $OSNAME eq 'MSWin32' ? 'MSWin' : $exec->shell->name;

my $quoter = Net::OpenSSH::ShellQuoter->quoter($shell);
$cmd = "$cmd " . join( " ", map { $quoter->quote($_) } @{$args} );
}

Expand Down
1 change: 1 addition & 0 deletions lib/Rex/Interface/Exec/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use warnings;
use Carp;
use Rex::Helper::Run;
use Rex::Commands::Fs;
use Rex::Interface::Shell;

our $VERSION = '9999.99.99_99'; # VERSION

Expand Down
30 changes: 30 additions & 0 deletions t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env perl

use v5.12.5;
use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use English qw(-no_match_vars);
use Test::More;
use Test::Warnings;

use Rex::Commands::Run;

plan tests => 3;

subtest 'simple command output', sub {
my $output = run 'echo 1';

if ( $OSNAME eq 'MSWin32' ) {
$output =~ s/[ ]$//msx;
}

is( $output, 1, 'correct output' );
};

subtest 'command with arguments', sub {
my $output = run 'perl', [ '-e', 'print 1' ];

is( $output, 1, 'correct output with arguments' );
};
Loading