Sha256: f694e446ea4efd9a918ba97847817f6b6dc23c590273489848264214c07cca06

Contents?: true

Size: 1000 Bytes

Versions: 10

Compression:

Stored size: 1000 Bytes

Contents

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
  # Windows-specific implementation details.
  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

10 entries across 10 versions & 2 rubygems

Version Path
fig-0.1.57 lib/fig/windows.rb
fig-0.1.55 lib/fig/windows.rb
fig-0.1.54 lib/fig/windows.rb
fig-0.1.53 lib/fig/windows.rb
fig-0.1.52 lib/fig/windows.rb
fig18-0.1.51-i386-mswin32 lib/fig/windows.rb
fig18-0.1.51-i386-mingw32 lib/fig/windows.rb
fig18-0.1.51 lib/fig/windows.rb
fig-0.1.51-java lib/fig/windows.rb
fig-0.1.51 lib/fig/windows.rb