Methods
Constants
| WINDOWS | = | Config::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)! |
| RUNNABLE_EXTS | = | %w[com exe bat cmd] |
| RUNNABLE_PATTERN | = | %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i |
Public Class methods
[ show source ]
# File lib/rake/alt_system.rb, line 35
35: def define_module_function(name, &block)
36: define_method(name, &block)
37: module_function(name)
38: end
Public Instance methods
[ show source ]
# File lib/rake/alt_system.rb, line 97
97: def backticks(cmd)
98: kernel_backticks(repair_command(cmd))
99: end
[ show source ]
# File lib/rake/alt_system.rb, line 70
70: def find_runnable(file)
71: if file =~ RUNNABLE_PATTERN
72: file
73: else
74: RUNNABLE_EXTS.each { |ext|
75: if File.exist?(test = "#{file}.#{ext}")
76: return test
77: end
78: }
79: nil
80: end
81: end
[ show source ]
# File lib/rake/alt_system.rb, line 50
50: def repair_command(cmd)
51: "call " + (
52: if cmd =~ %r!\A\s*\".*?\"!
53: # already quoted
54: cmd
55: elsif match = cmd.match(%r!\A\s*(\S+)!)
56: if match[1] =~ %r!/!
57: # avoid x/y.bat interpretation as x with option /y
58: %Q!"#{match[1]}"! + match.post_match
59: else
60: # a shell command will fail if quoted
61: cmd
62: end
63: else
64: # empty or whitespace
65: cmd
66: end
67: )
68: end
[ show source ]
# File lib/rake/alt_system.rb, line 83
83: def system(cmd, *args)
84: repaired = (
85: if args.empty?
86: [repair_command(cmd)]
87: elsif runnable = find_runnable(cmd)
88: [File.expand_path(runnable), *args]
89: else
90: # non-existent file
91: [cmd, *args]
92: end
93: )
94: kernel_system(*repaired)
95: end