Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #! /usr/bin/env ruby
  2. # -*- coding: utf-8 -*-
  3.  
  4. require "socket"
  5.  
  6. $sleep_time = ARGV[0].to_i || 3
  7.  
  8. puts "sleep_time: #{$sleep_time} sec"
  9.  
  10. s = nil
  11. until s
  12. begin
  13. s = TCPSocket.open("localhost", 10500)
  14. rescue
  15. STDERR.puts "Julius に接続失敗しました\n再接続を試みます"
  16. sleep 10
  17. retry
  18. end
  19. end
  20. puts "Julius に接続しました"
  21.  
  22. source = ""
  23. $ran_time = 1
  24. while true
  25. ret = IO::select([s])
  26. begin
  27. # データ取り出し
  28. ret[0].each do |sock|
  29. source += sock.recv(65535)
  30. end
  31. current_time = Time.now.to_i
  32. next if ($ran_time + $sleep_time) > current_time
  33. $ran_time = current_time
  34. # !!! ここでpythonプログラム叩く !!!
  35. puts system('print.py')
  36. hoge = Time.now.to_s
  37. puts "#{hoge} : プログラムを実行しました"
  38. # !!! ここでpythonプログラム叩く !!!
  39. rescue StandardError => e
  40. #puts "Error!!!!"
  41. #STDERR.puts e.backtrace.join("\n")
  42. rescue Exception => e
  43. s.close
  44. ensure
  45. #sleep $sleep_time
  46. end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement