Skip to content

Instantly share code, notes, and snippets.

@adampats
Created January 27, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampats/b1bdb665a133891d3bd7 to your computer and use it in GitHub Desktop.
Save adampats/b1bdb665a133891d3bd7 to your computer and use it in GitHub Desktop.
Ruby subthread stdout
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
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