From 83c8d9164fb6465fb589390134b9a00ce69c1e24 Mon Sep 17 00:00:00 2001 From: Thomas Heinen Date: Fri, 4 Oct 2024 14:56:42 +0200 Subject: [PATCH] Fix execution in target mode with cwd parameter given Signed-off-by: Thomas Heinen --- lib/mixlib/shellout/helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mixlib/shellout/helper.rb b/lib/mixlib/shellout/helper.rb index 1240712..c0a8fb8 100644 --- a/lib/mixlib/shellout/helper.rb +++ b/lib/mixlib/shellout/helper.rb @@ -158,7 +158,8 @@ def __shell_out_command(*args, **options) command = __join_whitespace(args) unless ChefUtils.windows? if options[:cwd] - command.prepend sprintf("cd %s;", options[:cwd]) + # as `timeout` is used, commands need to be executed in a subshell + command = "sh -c 'cd #{options[:cwd]}; #{command}'" end if options[:input]