# A small piece of code to prepare the script
# for 'script running' from FreeRIDE
BEGIN {

  # FreeRIDE must always intercept exits hence the exit! redefinition
  # at_exit sends a recognizable string to FreeRIDE
  module Kernel
    alias_method :exit!, :exit
  end
  
  # capture script exit and send a recognizable
  # pattern to FreeRIDE 
  at_exit do
    STDOUT.print "SS TT OO PP"
    STDOUT.flush
    STDERR.flush
  end
  
  # pausing - waiting for a go
  STDIN.gets
  # returns the current PID to FreeRIDE
  STDOUT.puts(Process.pid)
  STDOUT.flush
  # pausing again - waiting for another go from FreeRIDE
  STDIN.gets

}
