#!/usr/bin/ruby =begin 標準テスト起動用のスクリプト =end require 'pty' base_dir = File::dirname(__FILE__) STANDARD_TEST_BIN = "#{base_dir}/build_VC9/standard_test.exe" LOGGER_BIN = "#{base_dir}/../../note/070423/build_VC9/log_CSV.exe" LOGGER_OPTIONS = ["--direct_sylphide=on", "--page=A"].join(' ') LOGGER_FNAME_STRFTIME = "%Y%m%d-%H%M%S" BOT_BIN = "ruby.exe #{base_dir}/u_tokyo_13_bot.rb" $stderr.puts "Usage: #{__FILE__} cosmate_if epsec_if [sylphide_if0 ...]" if ARGV.size < 2 then $stderr.puts "ERROR: options is not enough!!" raise RuntimeError::new end loggers = [] deg = nil temp = nil # 各種Sylphideのログ取りの開始 if ARGV.size > 2 then ARGV[2..-1].each{|sylphide_if| log_fname = Time::now.strftime("#{LOGGER_FNAME_STRFTIME}") + "-#{sylphide_if}.csv" $stderr.puts "#{sylphide_if} => #{log_fname}" command = "#{LOGGER_BIN} #{sylphide_if} #{LOGGER_OPTIONS}" #.gsub(/\//, '\\') info = {} info[:line] = 0 info[:command] = command info[:fname] = log_fname info[:thread] = Thread::new{ open(log_fname, 'w'){|log| begin stdin, stdout, pid = PTY.spawn(command) info[:pid] = pid begin stdin.each{|line| info[:line] += 1 log.puts "#{line.chomp.chomp},#{deg},#{temp}" if info[:line] % 50000 == 0 then Thread::new{ system("#{BOT_BIN} '@fenrir_n #{info[:fname]} => #{info[:line]} 行'") } end } rescue Errno::EIO end rescue PTY::ChildExited $stderr.puts "info[:pid] exited..." end } # http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby } loggers << info } end # 恒温槽とターンテーブルの動作開始 IO::popen("#{STANDARD_TEST_BIN} #{ARGV[0]} #{ARGV[1]}"){|io| while true line = io.gets break unless line if line =~ /^Info: Deg (-?\d+); Temp (-?\d+)/ deg = $1.to_i temp = $2.to_i end puts line end } sleep 5 # ロギングの終了 loggers.each{|logger| sleep(1) until logger[:pid] $stderr.puts logger.inspect Process.kill(:KILL, logger[:pid]) logger[:thread].join }