Module: Mixlib::ShellOut::Windows::Utils
- Defined in:
- lib/mixlib/shellout/windows.rb
Class Method Summary collapse
- .executable?(path) ⇒ Boolean
-
.find_executable(path) ⇒ Object
Windows has a different notion of what “executable” means The OS will search through valid the extensions and look for a binary there.
- .pathext ⇒ Object
-
.should_run_under_cmd?(command) ⇒ Boolean
api: semi-private If there are special characters parsable by cmd.exe (such as file redirection), then this method should return true.
-
.which(cmd) ⇒ Object
which() mimicks the Unix which command FIXME: it is not working.
Class Method Details
.executable?(path) ⇒ Boolean
313 314 315 |
# File 'lib/mixlib/shellout/windows.rb', line 313 def self.executable?(path) File.executable?(path) && !File.directory?(path) end |
.find_executable(path) ⇒ Object
Windows has a different notion of what “executable” means The OS will search through valid the extensions and look for a binary there.
303 304 305 306 307 308 309 310 311 |
# File 'lib/mixlib/shellout/windows.rb', line 303 def self.find_executable(path) return path if executable? path pathext.each do |ext| exe = "#{path}#{ext}" return exe if executable? exe end return nil end |
.pathext ⇒ Object
286 287 288 |
# File 'lib/mixlib/shellout/windows.rb', line 286 def self.pathext @pathext ||= ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') + [''] : [''] end |
.should_run_under_cmd?(command) ⇒ Boolean
api: semi-private If there are special characters parsable by cmd.exe (such as file redirection), then this method should return true.
This parser is based on github.com/ruby/ruby/blob/9073db5cb1d3173aff62be5b48d00f0fb2890991/win32/win32.c#L1437
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/mixlib/shellout/windows.rb', line 252 def self.should_run_under_cmd?(command) return true if command =~ /^@/ quote = nil env = false env_first_char = false command.dup.each_char do |c| case c when "'", '"' if (!quote) quote = c elsif quote == c quote = nil end next when '>', '<', '|', '&', "\n" return true unless quote when '%' return true if env env = env_first_char = true next else next unless env if env_first_char env_first_char = false env = false and next if c !~ /[A-Za-z_]/ end env = false if c !~ /[A-Za-z1-9_]/ end end return false end |
.which(cmd) ⇒ Object
which() mimicks the Unix which command FIXME: it is not working
292 293 294 295 296 297 298 |
# File 'lib/mixlib/shellout/windows.rb', line 292 def self.which(cmd) ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exe = find_executable("#{path}/#{cmd}") return exe if exe end return nil end |