diff --git a/ChangeLog b/ChangeLog index 116f991e0..5747ffeb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ Revision history for Rex [DOCUMENTATION] [ENHANCEMENTS] + - Quote command arguments on Windows [MAJOR] diff --git a/lib/Rex/Commands/Run.pm b/lib/Rex/Commands/Run.pm index fd62615de..824d313d5 100644 --- a/lib/Rex/Commands/Run.pm +++ b/lib/Rex/Commands/Run.pm @@ -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/ ) { @@ -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} ); } diff --git a/lib/Rex/Interface/Exec/Base.pm b/lib/Rex/Interface/Exec/Base.pm index 089bf180a..e0990f6f0 100644 --- a/lib/Rex/Interface/Exec/Base.pm +++ b/lib/Rex/Interface/Exec/Base.pm @@ -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 diff --git a/t/run.t b/t/run.t new file mode 100755 index 000000000..dcc1b8050 --- /dev/null +++ b/t/run.t @@ -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' ); +};