Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- # -*- coding: utf-8 -*-
- require "socket"
- $sleep_time = ARGV[0].to_i || 3
- puts "sleep_time: #{$sleep_time} sec"
- s = nil
- until s
- begin
- s = TCPSocket.open("localhost", 10500)
- rescue
- STDERR.puts "Julius に接続失敗しました\n再接続を試みます"
- sleep 10
- retry
- end
- end
- puts "Julius に接続しました"
- source = ""
- $ran_time = 1
- while true
- ret = IO::select([s])
- begin
- # データ取り出し
- ret[0].each do |sock|
- source += sock.recv(65535)
- end
- current_time = Time.now.to_i
- next if ($ran_time + $sleep_time) > current_time
- $ran_time = current_time
- # !!! ここでpythonプログラム叩く !!!
- puts system('print.py')
- hoge = Time.now.to_s
- puts "#{hoge} : プログラムを実行しました"
- # !!! ここでpythonプログラム叩く !!!
- rescue StandardError => e
- #puts "Error!!!!"
- #STDERR.puts e.backtrace.join("\n")
- rescue Exception => e
- s.close
- ensure
- #sleep $sleep_time
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement