module Rake::AltSystem

  1. lib/rake/alt_system.rb
Parent: Rake

Alternate implementations of system() and backticks `` on Windows for ruby-1.8 and earlier.

Methods

Public Class

  1. define_module_function

Public Instance

  1. repair_command
  2. find_runnable
  3. system
  4. backticks

Constants

WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!  
RUNNABLE_EXTS = %w[com exe bat cmd]  
RUNNABLE_PATTERN = %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i  

Public Class methods

define_module_function (name, &block)
[show source]
    # File lib/rake/alt_system.rb, line 36
36:     def define_module_function(name, &block)
37:       define_method(name, &block)
38:       module_function(name)
39:     end

Public Instance methods

repair_command (cmd)
[show source]
    # File lib/rake/alt_system.rb, line 51
51:     def repair_command(cmd)
52:       "call " + (
53:         if cmd =~ %\A\s*\".*?\"!
54:           # already quoted
55:           cmd
56:         elsif match = cmd.match(%\A\s*(\S+)!)
57:           if match[1] =~ %/!
58:             # avoid x/y.bat interpretation as x with option /y
59:             %"#{match[1]}"! + match.post_match
60:           else
61:             # a shell command will fail if quoted
62:             cmd
63:           end
64:         else
65:           # empty or whitespace
66:           cmd
67:         end
68:       )
69:     end
find_runnable (file)
[show source]
    # File lib/rake/alt_system.rb, line 71
71:     def find_runnable(file)
72:       if file =~ RUNNABLE_PATTERN
73:         file
74:       else
75:         RUNNABLE_EXTS.each { |ext|
76:           if File.exist?(test = "#{file}.#{ext}")
77:             return test
78:           end
79:         }
80:         nil
81:       end
82:     end
system (cmd, *args)
[show source]
    # File lib/rake/alt_system.rb, line 84
84:     def system(cmd, *args)
85:       repaired = (
86:         if args.empty?
87:           [repair_command(cmd)]
88:         elsif runnable = find_runnable(cmd)
89:           [File.expand_path(runnable), *args]
90:         else
91:           # non-existent file
92:           [cmd, *args]
93:         end
94:       )
95:       kernel_system(*repaired)
96:     end
backticks (cmd)
[show source]
     # File lib/rake/alt_system.rb, line 98
 98:     def backticks(cmd)
 99:       kernel_backticks(repair_command(cmd))
100:     end