From 57e0fbd2f921defcb75163cd0cd0f1751e85166e Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 17 Apr 2023 00:39:49 +0200 Subject: [PATCH 1/2] Test switching working directory of execution --- t/issue/1583.t | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 t/issue/1583.t diff --git a/t/issue/1583.t b/t/issue/1583.t new file mode 100755 index 000000000..508af86bf --- /dev/null +++ b/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' ); From e1398a1d3bd2b95ef02c43b8d49fd8c1919515cf Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 17 Apr 2023 01:27:34 +0200 Subject: [PATCH 2/2] Fix switching working directory to another drive --- ChangeLog | 1 + lib/Rex/Interface/Exec/Local.pm | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4d874251c..eeea23d51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Fix switching working directory to another drive [DOCUMENTATION] diff --git a/lib/Rex/Interface/Exec/Local.pm b/lib/Rex/Interface/Exec/Local.pm index cf12a09df..609eef52e 100644 --- a/lib/Rex/Interface/Exec/Local.pm +++ b/lib/Rex/Interface/Exec/Local.pm @@ -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; @@ -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} ) {