Skip to content

Commit 2dfe610

Browse files
committed
Merge pull request #1635 from RexOps/windows_command_env
Support command environment variables on Windows
2 parents b18d302 + eb8cbc4 commit 2dfe610

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Revision history for Rex
99

1010
[ENHANCEMENTS]
1111
- Quote command arguments on Windows
12+
- Support command environment variables on Windows
1213

1314
[MAJOR]
1415

lib/Rex/Interface/Exec/Local.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sub set_env {
3939
if ( ref $env ne "HASH" );
4040

4141
while ( my ( $k, $v ) = each(%$env) ) {
42-
$cmd .= "export $k='$v'; ";
42+
$cmd .= $OSNAME eq 'MSWin32' ? "set $k=$v && " : "export $k='$v'; ";
4343
}
4444
$self->{env} = $cmd;
4545
}
@@ -87,6 +87,11 @@ sub exec {
8787

8888
$cmd = $new_cmd;
8989
}
90+
else {
91+
if ( $self->{env} ) {
92+
$cmd = $self->{env} . " $cmd";
93+
}
94+
}
9095

9196
Rex::Logger::debug("Executing: $cmd");
9297

t/env.t

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use Rex::Commands::Run;
1212

1313
$::QUIET = 1;
1414

15-
SKIP: {
16-
skip 'Do not run tests on Windows', 1 if $^O =~ m/^MSWin/;
15+
my $s = run( 'perl', [ '-e', 'print $ENV{REX}' ], env => { 'REX' => 'XER' } );
1716

18-
my $s = run( q(perl -e 'print $ENV{REX}'), env => { 'REX' => 'XER' } );
19-
like( $s, qr/XER/, "run with env" );
20-
}
17+
like( $s, qr/XER/, "run with env" );

t/scm/git.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use Test::More;
99
use Test::Warnings;
1010
use Test::Exception;
1111

12+
use English qw(-no_match_vars);
1213
use File::Spec;
1314
use File::Temp qw(tempdir);
1415
use Rex::Commands;
@@ -27,9 +28,11 @@ else {
2728
plan skip_all => 'Can not find git command';
2829
}
2930

31+
my $empty_config_file = $OSNAME eq 'MSWin32' ? q() : File::Spec->devnull();
32+
3033
my $git_environment = {
31-
GIT_CONFIG_GLOBAL => File::Spec->devnull(),
32-
GIT_CONFIG_SYSTEM => File::Spec->devnull(),
34+
GIT_CONFIG_GLOBAL => $empty_config_file,
35+
GIT_CONFIG_SYSTEM => $empty_config_file,
3336
};
3437

3538
ok( $git, "Found git command at $git" );

0 commit comments

Comments
 (0)