Sha256: 3aaa1c631dc54acead8440adbb6756a042523190e1e3fcef3229a3a9d01637da
Contents?: true
Size: 1013 Bytes
Versions: 40
Compression:
Stored size: 1013 Bytes
Contents
# Keeping Windows-specific implementation details here. require 'erb' require 'fileutils' # I don't know how to set environment variables so that a sub-shell will # be able to use them. Therefore, I'm punting, and creating a batch script # on the fly to run a user supplied command. module Fig class Windows BATCH_SCRIPT_TEMPLATE = <<EOF @echo off % ENV.each do |k,v| set <%= k %>=<%= v %> % end cmd /C <%= command %> EOF 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 def self.shell_exec_windows(cmd) with_generated_batch_script(cmd) do |f| Kernel.exec(f) end end end end
Version data entries
40 entries across 40 versions & 2 rubygems