Created
January 27, 2016 19:08
-
-
Save adampats/b1bdb665a133891d3bd7 to your computer and use it in GitHub Desktop.
Ruby subthread stdout
This file contains 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
require 'open3' | |
puts "test1.rb" | |
Open3.popen3("ruby test2.rb") do |stdin, stdout, stderr, wait_thr| | |
while line = stdout.gets do | |
puts line | |
end | |
end |
This file contains 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
require 'socket' | |
puts "#{Time.now}" | |
puts "Starting socket server..." | |
server = TCPServer.new 2000 | |
loop do | |
client = server.accept | |
client.puts "Time is #{Time.now}" | |
while line = client.gets | |
puts line.chomp | |
break if line =~ /^\s*$/ | |
end | |
client.close | |
break | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment