Sha256: 7ed436047bc54867e5e418b63adaf99c64cb0bbc439e29feff22ff76e2540957

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

module ChildProcess
  module Windows
    class Process < AbstractProcess

      attr_reader :pid

      def io
        @io ||= Windows::IO.new
      end

      def stop(timeout = 3)
        assert_started

        # just kill right away on windows.
        log "sending KILL"
        @handle.send(WIN_SIGKILL)

        poll_for_exit(timeout)
      ensure
        @handle.close
      end

      def wait
        @handle.wait
        @exit_code = @handle.exit_code
      end

      def exited?
        return true if @exit_code
        assert_started

        code   = @handle.exit_code
        exited = code != PROCESS_STILL_ACTIVE

        log(:exited? => exited, :code => code)

        if exited
          @exit_code = code
        end

        exited
      end

      private

      def launch_process
        opts = {
          :inherit     => false,
          :detach      => detach?,
          :duplex      => duplex?,
          :environment => (@environment unless @environment.empty?)
        }

        if @io
          opts[:stdout] = @io.stdout
          opts[:stderr] = @io.stderr
        end

        @pid = Lib.create_proc(command_string, opts)
        @handle = Handle.open(@pid)

        if duplex?
          io._stdin = opts[:stdin]
        end

        self
      end

      def command_string
        @command_string ||= (
          @args.map { |arg| quote_if_necessary(arg.to_s) }.join ' '
        )
      end

      def quote_if_necessary(str)
        quote = str.start_with?('"') ? "'" : '"'

        case str
        when /[\s\\'"]/
          %{#{quote}#{str}#{quote}}
        else
          str
        end
      end

    end # Process
  end # Windows
end # ChildProcess

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
childprocess-0.2.5 lib/childprocess/windows/process.rb
childprocess-0.2.4 lib/childprocess/windows/process.rb