Module: Brush::Pipeline::Win32
- Included in:
- Brush::Pipeline
- Defined in:
- lib/brush/pipeline.rb
Instance Method Summary collapse
- #create_process(argv, options, close_pipes) ⇒ Object
- #each_pathext_element ⇒ Object
- #find_in_path(name) ⇒ Object
- #make_handle_inheritable(io, inheritable = true) ⇒ Object
- #sys_wait(process_info) ⇒ Object
Instance Method Details
#create_process(argv, options, close_pipes) ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/brush/pipeline.rb', line 425 def create_process (argv, , close_pipes) close_pipes.each do |io| make_handle_inheritable(io, false) end Brush::Pipeline::PARENT_PIPES.each_key do |io| make_handle_inheritable(io, false) end [:stdin, :stdout, :stderr].each do |io_sym| make_handle_inheritable([io_sym]) if [io_sym] end Dir.chdir([:cd]) do return Process.create( :app_name => [:executable], :command_line => Escape.shell_command(argv), :inherit => true, :close_handles => false, :creation_flags => Process::CREATE_NO_WINDOW, :startup_info => { :startf_flags => Process::STARTF_USESTDHANDLES, :stdin => [:stdin], :stdout => [:stdout], :stderr => [:stderr] }) end end |
#each_pathext_element ⇒ Object
489 490 491 |
# File 'lib/brush/pipeline.rb', line 489 def each_pathext_element ENV['PATHEXT'].split(File::PATH_SEPARATOR).each { |ext| yield ext } end |
#find_in_path(name) ⇒ Object
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/brush/pipeline.rb', line 455 def find_in_path (name) chkname = nil if name =~ %r"[:/\\]" # Path is absolute or relative. basename = File.basename(name) fullname = File.(name) if basename =~ /\./ # Path comes with extension. return fullname else # Need to find extension. each_pathext_element do |ext| return chkname if File.exists?(chkname = [fullname, ext].join) end end elsif name =~ /\./ # Given extension. each_path_element do |dir| return chkname if File.exists?(chkname = File.join(dir, name)) end else # Just a nameāno path or extension. each_path_element do |dir| each_pathext_element do |ext| if File.exists?(chkname = File.join(dir, [name, ext].join)) return chkname end end end end nil # Didn't find a match. :( end |
#make_handle_inheritable(io, inheritable = true) ⇒ Object
415 416 417 418 419 420 421 422 |
# File 'lib/brush/pipeline.rb', line 415 def make_handle_inheritable (io, inheritable = true) if not SetHandleInformation( get_osfhandle(io.fileno), Windows::Handle::HANDLE_FLAG_INHERIT, inheritable ? Windows::Handle::HANDLE_FLAG_INHERIT : 0) \ then raise Error, get_last_error end end |
#sys_wait(process_info) ⇒ Object
407 408 409 410 411 412 |
# File 'lib/brush/pipeline.rb', line 407 def sys_wait (process_info) numeric_status = Process.waitpid2(process_info.process_id)[1] Process.CloseHandle(process_info.process_handle) Process.CloseHandle(process_info.thread_handle) duck_type_status_object(Object.new, process_info.process_id, numeric_status) end |