Class: Fig::Windows

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

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



40
41
42
43
44
# File 'lib/fig/windows.rb', line 40

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

.with_generated_batch_script(cmd) ⇒ Object



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

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