Last active
August 29, 2015 14:04
-
-
Save advorak/38647fa0752399beaf64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I am executing a program 'umessage' and piping output to this | |
# ruby script ... | |
# | |
# The problem is that I'm noticing my program isn't receiving all | |
# of the output I expect it to receive from STDOUT to STDIN...... | |
# It is consistently skipping data... any hints as to what I'm | |
# doing wrong? | |
DEBUG = true | |
@user_id = 5 | |
@current_data = '' | |
while(data = $stdin.sysread(100).to_s) | |
sleep 0.25 if data.blank? | |
data = @current_data.to_s + data | |
@current_data = '' | |
messages = data.lines.slice_before(/^\d{2}\/\d{2}/).collect(&:join) | |
messages.each do |message| | |
if [message].join.match(/\n$/) | |
UMessage.create user_id: @user_id, data: message | |
else | |
@current_data = [message].join | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment