diff --git a/ChangeLog b/ChangeLog index 5747ffeb1..7f74a27ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ Revision history for Rex [ENHANCEMENTS] - Quote command arguments on Windows + - Support command environment variables on Windows [MAJOR] diff --git a/lib/Rex/Interface/Exec/Local.pm b/lib/Rex/Interface/Exec/Local.pm index 609eef52e..221475cc9 100644 --- a/lib/Rex/Interface/Exec/Local.pm +++ b/lib/Rex/Interface/Exec/Local.pm @@ -39,7 +39,7 @@ sub set_env { if ( ref $env ne "HASH" ); while ( my ( $k, $v ) = each(%$env) ) { - $cmd .= "export $k='$v'; "; + $cmd .= $OSNAME eq 'MSWin32' ? "set $k=$v && " : "export $k='$v'; "; } $self->{env} = $cmd; } @@ -87,6 +87,11 @@ sub exec { $cmd = $new_cmd; } + else { + if ( $self->{env} ) { + $cmd = $self->{env} . " $cmd"; + } + } Rex::Logger::debug("Executing: $cmd"); diff --git a/t/env.t b/t/env.t index 7eb6d21bf..17cebc4e6 100755 --- a/t/env.t +++ b/t/env.t @@ -12,9 +12,6 @@ use Rex::Commands::Run; $::QUIET = 1; -SKIP: { - skip 'Do not run tests on Windows', 1 if $^O =~ m/^MSWin/; +my $s = run( 'perl', [ '-e', 'print $ENV{REX}' ], env => { 'REX' => 'XER' } ); - my $s = run( q(perl -e 'print $ENV{REX}'), env => { 'REX' => 'XER' } ); - like( $s, qr/XER/, "run with env" ); -} +like( $s, qr/XER/, "run with env" ); diff --git a/t/scm/git.t b/t/scm/git.t index d879e381a..77999f7af 100755 --- a/t/scm/git.t +++ b/t/scm/git.t @@ -9,6 +9,7 @@ use Test::More; use Test::Warnings; use Test::Exception; +use English qw(-no_match_vars); use File::Spec; use File::Temp qw(tempdir); use Rex::Commands; @@ -27,9 +28,11 @@ else { plan skip_all => 'Can not find git command'; } +my $empty_config_file = $OSNAME eq 'MSWin32' ? q() : File::Spec->devnull(); + my $git_environment = { - GIT_CONFIG_GLOBAL => File::Spec->devnull(), - GIT_CONFIG_SYSTEM => File::Spec->devnull(), + GIT_CONFIG_GLOBAL => $empty_config_file, + GIT_CONFIG_SYSTEM => $empty_config_file, }; ok( $git, "Found git command at $git" );