Skip to content

Commit 6f1ca15

Browse files
committed
Use IO.popen to start a process
RuboCop rightfully complains about using open() to spawn a process. This uses the way simpler IO.popen() method.
1 parent fc39fe4 commit 6f1ca15

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

lib/puppet/util/execution.rb

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,14 @@ def initialize(value, exitstatus)
5757
# @see Kernel#open for `mode` values
5858
# @api public
5959
def self.execpipe(command, failonfail = true)
60-
# Paste together an array with spaces. We used to paste directly
61-
# together, no spaces, which made for odd invocations; the user had to
62-
# include whitespace between arguments.
63-
#
64-
# Having two spaces is really not a big drama, since this passes to the
65-
# shell anyhow, while no spaces makes for a small developer cost every
66-
# time this is invoked. --daniel 2012-02-13
67-
command_str = command.respond_to?(:join) ? command.join(' ') : command
68-
6960
if respond_to? :debug
70-
debug "Executing '#{command_str}'"
61+
debug "Executing #{command.inspect}"
7162
else
72-
Puppet.debug { "Executing '#{command_str}'" }
63+
Puppet.debug { "Executing #{command.inspect}" }
7364
end
7465

75-
# force the run of the command with
76-
# the user/system locale to "C" (via environment variables LANG and LC_*)
77-
# it enables to have non localized output for some commands and therefore
78-
# a predictable output
79-
english_env = ENV.to_hash.merge({ 'LANG' => 'C', 'LC_ALL' => 'C' })
80-
output = Puppet::Util.withenv(english_env) do
81-
# We are intentionally using 'pipe' with open to launch a process
82-
open("| #{command_str} 2>&1") do |pipe| # rubocop:disable Security/Open
83-
yield pipe
84-
end
66+
output = IO.popen({ 'LANG' => 'C', 'LC_ALL' => 'C' }, command, err: :out) do |pipe|
67+
yield pipe
8568
end
8669

8770
if failonfail && exitstatus != 0

0 commit comments

Comments
 (0)