Module: Puppet::Util::Windows::Process

Extended by:
Windows::Handle, Windows::Process, Windows::Synchronize
Defined in:
lib/vendor/puppet/util/windows/process.rb

Class Method Summary collapse

Class Method Details

.execute(command, arguments, stdin, stdout, stderr) ⇒ Object



8
9
10
# File 'lib/vendor/puppet/util/windows/process.rb', line 8

def execute(command, arguments, stdin, stdout, stderr)
  Process.create( :command_line => command, :startup_info => {:stdin => stdin, :stdout => stdout, :stderr => stderr}, :close_handles => false )
end

.wait_process(handle) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vendor/puppet/util/windows/process.rb', line 13

def wait_process(handle)
  while WaitForSingleObject(handle, 0) == Windows::Synchronize::WAIT_TIMEOUT
    sleep(1)
  end

  exit_status = [0].pack('L')
  unless GetExitCodeProcess(handle, exit_status)
    raise Puppet::Util::Windows::Error.new("Failed to get child process exit code")
  end
  exit_status = exit_status.unpack('L').first

  # $CHILD_STATUS is not set when calling win32/process Process.create
  # and since it's read-only, we can't set it. But we can execute a
  # a shell that simply returns the desired exit status, which has the
  # desired effect.
  %x{#{ENV['COMSPEC']} /c exit #{exit_status}}

  exit_status
end