# Script Exiting Unexpectedly

**URL:** <https://www.ruby-forum.com/t/script-exiting-unexpectedly/82578>\
**Category:** Ruby\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/script-exiting-unexpectedly/82578 "2007-01-19T16:31:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregarican](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7feea3/32.png) [@gregarican](https://www.ruby-forum.com/u/gregarican)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/script-exiting-unexpectedly/82578/1 "2007-01-19T16:31:29Z")

</div>

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
