From cbed52a5ab2f5d471982a370b51566cc3bd9c74d Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sun, 19 Jan 2025 19:57:03 +0100 Subject: [PATCH 1/3] Add initial run command test --- t/run.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 t/run.t diff --git a/t/run.t b/t/run.t new file mode 100755 index 000000000..76e0eaeca --- /dev/null +++ b/t/run.t @@ -0,0 +1,24 @@ +#!/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 => 2; + +subtest 'simple command output', sub { + my $output = run 'echo 1'; + + if ( $OSNAME eq 'MSWin32' ) { + $output =~ s/[ ]$//msx; + } + + is( $output, 1, 'correct output' ); +}; From 27d9bf59699edb7c06ca16431f0bc234f8136259 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sun, 19 Jan 2025 20:29:47 +0100 Subject: [PATCH 2/3] Add test for command with arguments --- t/run.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/t/run.t b/t/run.t index 76e0eaeca..dcc1b8050 100755 --- a/t/run.t +++ b/t/run.t @@ -11,7 +11,7 @@ use Test::Warnings; use Rex::Commands::Run; -plan tests => 2; +plan tests => 3; subtest 'simple command output', sub { my $output = run 'echo 1'; @@ -22,3 +22,9 @@ subtest 'simple command output', sub { is( $output, 1, 'correct output' ); }; + +subtest 'command with arguments', sub { + my $output = run 'perl', [ '-e', 'print 1' ]; + + is( $output, 1, 'correct output with arguments' ); +}; From 5ff7fcbd7cab3630200c6e4e75c36b83658a7581 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sun, 19 Jan 2025 20:40:32 +0100 Subject: [PATCH 3/3] Quote command arguments on Windows --- ChangeLog | 1 + lib/Rex/Commands/Run.pm | 6 +++++- lib/Rex/Interface/Exec/Base.pm | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) 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