AGI ruby not recognizing end-of-line

I have a very simple ruby script that I am trying to execute from AGI that gets a global variable, and it has me really confused. I am able to read the agi variables that come in, and I can see from AGI debug that when I give it a “GET VARIABLE” command that it is returning the value (42 in my example) that it is supposed to, but the script hangs up as if it does not recognize the end of line. in Bash a "read’ works, but i can not make it work with ruby.

Any assistance would me much appreciated!

Here is my dial plan

exten => 9,1,NoOp()
   same => n,Answer()
   same => n,AGI(test.rb)
   same => n,Hangup()

And my ruby script


testfile ="/tmp/test_out.log", "a")  #capture output
parameters = #hah for parameters
while (line = STDIN.gets) && (line != "\n") #populates hash where parameter is key and value is value
   inputs = line.split(": ")
   parameters[inputs.first] = inputs.last.chomp
testfile.puts parameters #dumps array of parameters
puts "GET VARIABLE v_global_test_val" #AGI command to get a variable
v_input = gets # capture it 
testfile.puts v_input

and my cli output after I dial 9

ivrsandbox*CLI> == Using SIP RTP CoS mark 5 -- Executing [9@test_in:1] NoOp("SIP/sp2-00000044", "") in new stack -- Executing [9@test_in:2] Answer("SIP/sp2-00000044", "") in new stack -- Executing [9@test_in:3] AGI("SIP/sp2-00000044", "test.rb") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/test.rb <SIP/sp2-00000044>AGI Tx >> agi_request: test.rb <SIP/sp2-00000044>AGI Tx >> agi_channel: SIP/sp2-00000044 <SIP/sp2-00000044>AGI Tx >> agi_language: en <SIP/sp2-00000044>AGI Tx >> agi_type: SIP <SIP/sp2-00000044>AGI Tx >> agi_uniqueid: 1393394014.68 <SIP/sp2-00000044>AGI Tx >> agi_version: 11.7.0 <SIP/sp2-00000044>AGI Tx >> agi_callerid: sp2 <SIP/sp2-00000044>AGI Tx >> agi_calleridname: unknown <SIP/sp2-00000044>AGI Tx >> agi_callingpres: 0 <SIP/sp2-00000044>AGI Tx >> agi_callingani2: 0 <SIP/sp2-00000044>AGI Tx >> agi_callington: 0 <SIP/sp2-00000044>AGI Tx >> agi_callingtns: 0 <SIP/sp2-00000044>AGI Tx >> agi_dnid: 9 <SIP/sp2-00000044>AGI Tx >> agi_rdnis: unknown <SIP/sp2-00000044>AGI Tx >> agi_context: test_in <SIP/sp2-00000044>AGI Tx >> agi_extension: 9 <SIP/sp2-00000044>AGI Tx >> agi_priority: 3 <SIP/sp2-00000044>AGI Tx >> agi_enhanced: 0.0 <SIP/sp2-00000044>AGI Tx >> agi_accountcode: <SIP/sp2-00000044>AGI Tx >> agi_threadid: 139646128731904 <SIP/sp2-00000044>AGI Tx >> ivrsandbox*CLI>

and the remainder of of the CLI output I get when I hang up

<SIP/sp2-00000044>AGI Tx >> <SIP/sp2-00000044>AGI Rx << GET VARIABLE v_global_test_val <SIP/sp2-00000044>AGI Tx >> 200 result=1 (42) -- <SIP/sp2-00000044>AGI Script test.rb completed, returning 4 == Spawn extension (test_in, 9, 3) exited non-zero on 'SIP/sp2-00000044' ivrsandbox*CLI>