Class: ChildProcess::Windows::Handle

### Home Classes Methods

### In Files

- lib/childprocess/windows/handle.rb

### Parent

Object

### Methods

- ::new
- ::open
- #close
- #exit_code
- #send
- #wait

### Class/Module Index

Quicksearch

- ChildProcess
- ChildProcess::AbstractIO
- ChildProcess::AbstractProcess
- ChildProcess::Error
- ChildProcess::InvalidEnvironmentVariable
- ChildProcess::JRuby
- ChildProcess::JRuby::IO
- ChildProcess::JRuby::Process
- ChildProcess::JRuby::Pump
- ChildProcess::LaunchError
- ChildProcess::MissingPlatformError
- ChildProcess::SubclassResponsibility
- ChildProcess::TimeoutError
- ChildProcess::Tools
- ChildProcess::Tools::Generator
- ChildProcess::Unix
- ChildProcess::Unix::ForkExecProcess
- ChildProcess::Unix::IO
- ChildProcess::Unix::Lib
- ChildProcess::Unix::Lib::Attrs
- ChildProcess::Unix::Lib::FileActions
- ChildProcess::Unix::Platform
- ChildProcess::Unix::PosixSpawnProcess
- ChildProcess::Unix::PosixSpawnProcess::Argv
- ChildProcess::Unix::PosixSpawnProcess::Envp
- ChildProcess::Unix::Process
- ChildProcess::Windows
- ChildProcess::Windows::Handle
- ChildProcess::Windows::IO
- ChildProcess::Windows::IoCounters
- ChildProcess::Windows::JobObjectBasicLimitInformation
- ChildProcess::Windows::JobObjectExtendedLimitInformation
- ChildProcess::Windows::Lib
- ChildProcess::Windows::Process
- ChildProcess::Windows::Process::Job
- ChildProcess::Windows::ProcessBuilder
- ChildProcess::Windows::ProcessInfo
- ChildProcess::Windows::SecurityAttributes
- ChildProcess::Windows::StartupInfo
- Java
- Java::JavaIo
- Java::JavaIo::FileDescriptor
- Java::SunNioCh
- Java::SunNioCh::FileChannelImpl
- FFI
- FFI::MemoryPointer

No matching classes.

# ChildProcess::Windows::Handle

### Attributes

pointer[R]

### Public Class Methods

new(pointer, pid) click to toggle source

    # File lib/childprocess/windows/handle.rb, line 28
    def initialize(pointer, pid)
      unless pointer.kind_of?(FFI::Pointer)
        raise TypeError, "invalid handle: #{pointer.inspect}"
      end

      if pointer.null?
        raise ArgumentError, "handle is null: #{pointer.inspect}"
      end

      @pid     = pid
      @pointer = pointer
      @closed  = false
    end

open(pid, access = PROCESS_ALL_ACCESS) click to toggle source

    # File lib/childprocess/windows/handle.rb, line 8
    def open(pid, access = PROCESS_ALL_ACCESS)
      handle = Lib.open_process(access, false, pid)

      if handle.null?
        raise Error, Lib.last_error_message
      end

      h = new(handle, pid)
      return h unless block_given?

      begin
        yield h
      ensure
        h.close
      end
    end

### Public Instance Methods

close() click to toggle source

    # File lib/childprocess/windows/handle.rb, line 78
    def close
      return if @closed

      Lib.close_handle(@pointer)
      @closed = true
    end

exit_code() click to toggle source

    # File lib/childprocess/windows/handle.rb, line 42
    def exit_code
      code_pointer = FFI::MemoryPointer.new :ulong
      ok = Lib.get_exit_code(@pointer, code_pointer)

      if ok
        code_pointer.get_ulong(0)
      else
        close
        raise Error, Lib.last_error_message
      end
    end

send(signal) click to toggle source

    # File lib/childprocess/windows/handle.rb, line 54
    def send(signal)
      case signal
      when 0
        exit_code == PROCESS_STILL_ALIVE
      when WIN_SIGINT
        Lib.generate_console_ctrl_event(CTRL_C_EVENT, @pid)
      when WIN_SIGBREAK
        Lib.generate_console_ctrl_event(CTRL_BREAK_EVENT, @pid)
      when WIN_SIGKILL
        ok = Lib.terminate_process(@pointer, @pid)
        Lib.check_error ok
      else
        thread_id     = FFI::MemoryPointer.new(:ulong)
        module_handle = Lib.get_module_handle("kernel32")
        proc_address  = Lib.get_proc_address(module_handle, "ExitProcess")

        thread = Lib.create_remote_thread(@pointer, 0, 0, proc_address, 0, 0, thread_id)
        check_error thread

        Lib.wait_for_single_object(thread, 5)
        true
      end
    end

wait(milliseconds = nil) click to toggle source

    # File lib/childprocess/windows/handle.rb, line 85
    def wait(milliseconds = nil)
      Lib.wait_for_single_object(@pointer, milliseconds || INFINITE)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.