Class: Fig::Windows

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/windows.rb

Overview

Windows-specific implementation details.

Constant Summary collapse

BATCH_SCRIPT_TEMPLATE =
<<EOF
@echo off
% ENV.each do |k,v|
set <%= k %>=<%= v %>
% end

cmd /C <%= command %>
EOF

Class Method Summary collapse

Class Method Details

.shell_exec_windows(cmd) ⇒ Object



38
39
40
41
42
# File 'lib/fig/windows.rb', line 38

def self.shell_exec_windows(cmd)
  with_generated_batch_script(cmd) do |f|
    Kernel.exec(f)
  end
end

.with_generated_batch_script(cmd) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fig/windows.rb', line 21

def self.with_generated_batch_script(cmd)
  command = cmd.join(' ')
  template = ERB.new(BATCH_SCRIPT_TEMPLATE, 0, '%')
  output = template.result(binding)
  begin
    tf = File.new('C:/tmp/fig_command.bat', 'w')
    FileUtils.chmod(0755, tf.path)
    File.open(tf.path, 'w') do |fh|
      fh.puts output
    end
    tf.close
    yield tf.path
  ensure
#        tf.delete
  end
end