Skip to content

Commit

Permalink
Merge pull request #1584 from RexOps/i_run_cwd
Browse files Browse the repository at this point in the history
Fix switching working directory to another drive
  • Loading branch information
ferki committed Apr 17, 2023
2 parents 3a57c93 + e1398a1 commit 1409355
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -4,6 +4,7 @@ Revision history for Rex
[API CHANGES]

[BUG FIXES]
- Fix switching working directory to another drive

[DOCUMENTATION]

Expand Down
4 changes: 3 additions & 1 deletion lib/Rex/Interface/Exec/Local.pm
Expand Up @@ -12,6 +12,7 @@ our $VERSION = '9999.99.99_99'; # VERSION
use Rex::Logger;
use Rex::Commands;

use English qw(-no_match_vars);
use Symbol 'gensym';
use IPC::Open3;
use IO::Select;
Expand Down Expand Up @@ -49,7 +50,8 @@ sub exec {
my ( $out, $err, $pid );

if ( exists $option->{cwd} ) {
$cmd = "cd " . $option->{cwd} . " && $cmd";
my $cd_cmd = $OSNAME eq 'MSWin32' ? 'cd /d' : 'cd';
$cmd = "$cd_cmd " . $option->{cwd} . " && $cmd";
}

if ( exists $option->{path} ) {
Expand Down
19 changes: 19 additions & 0 deletions t/issue/1583.t
@@ -0,0 +1,19 @@
#!/usr/bin/env perl

use v5.12.5;
use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use Test::More tests => 1;

use English qw(-no_match_vars);
use File::Spec;
use Rex::Helper::Run;

my $cmd = $OSNAME eq 'MSWin32' ? 'cd' : 'pwd';

my $target_dir = File::Spec->tmpdir();
my $dir = i_run $cmd, cwd => $target_dir;

is( $dir, $target_dir, 'switch to temp directory' );

0 comments on commit 1409355

Please sign in to comment.