Forum: Ruby Script Exiting Unexpectedly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
33ec7e55a251c1be8d6febfd929aebbe?d=identicon&s=25 Greg Kujawa (gregarican)
on 2007-01-19 16:31
(Received via mailing list)
A script I wrote checks incoming caller ID's against Microsoft
Outlook's Contact list. What I've found is that without explicitly
including a 'return' line in the conditional routine the script exits
unexpectedly. I've commented out the explicit return statement that's
required. Any ideas why this is the case? I'm using Ruby 1.8.2 on
Win32. I've traced the script and found that it doesn't bomb out with
any errors that I can tell. The only difference is the line that's
commented with HEADS-UP. Maybe I can't see the forest through the trees
:-/

outlookScreenPop.rb snippet
------------------------------------------

# My screen pop method
def screenPop(alertingCall)
  allContacts = getContacts

  # Continue with the screen pop query if data was passed back from the
Outlook OLE link.
  if allContacts != nil
    # Iterate through each contact to determine its associated telephone
numbers
    allContacts.each do | contact |
      cleanHomePhone = clean(contact.HomeTelephoneNumber)
      cleanBusPhone = clean(contact.BusinessTelephoneNumber)
      cleanCellPhone = clean(contact.MobileTelephoneNumber)

      puts "#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")} -
Testing #{cleanHomePhone} | #{cleanBusPhone} | #{cleanCellPhone}
against #{alertingCall}."

      # Match them up, append the entry to the logfile and display the
Contact Record
      if alertingCall == cleanHomePhone or alertingCall == cleanBusPhone
or alertingCall == cleanCellPhone
        puts "#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")} -
#{alertingCall} matched against #{contact.FullName} in Outlook
Contacts."
        contact.Display
        return
      end
      # HEADS-UP!!! Here's the explicit return statement that seems to
be
necessary --- return
    end
  else
    puts "#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")} - No
records found in Outlook Contacts or OLE link broken."
    exit
  end
end

# My loop that checks for incoming calls
begin
  # Check the monitor every half second for an alerting call.
  loop do
    sleep 0.5
    if @tsession.ringing?

      # If the extension has an alerting call, collect the data.
      @caller=@tsession.callIdMon
      @callingNum=@tsession.callDevIdMon

      # If the call isn't originating from the extension itelf, pop up a
Windows message box with the caller ID and attempt an Outlook Contact
screen pop.
      if @callingNum != @extension
        puts "#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")} -
#{@callingNum} calling."
        Win32API.new("user32", "MessageBox", ['i','p','p','i'],
'i').call(0, "#{@callingNum} calling on
#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")}.", "Mojo CTI
Link", 0)
        screenPop(@callingNum) if @callingNum != ""
      end
    end
  end
ensure
  @tsession.close
  puts "#{Time.now.localtime.strftime("%m/%d/%Y @ %H:%M:%S")} - Closed
CTI stream from #{@extension}."
  exit
end
This topic is locked and can not be replied to.