Windows+Rubyã§å¤é¨ããã»ã¹ãç«ã¡ä¸ããæã®æ³¨æ
Windowsä¸ã§ãRubyããå¤é¨ããã»ã¹*1ãèµ·åãçµäºç£è¦ããæ¹æ³ã®ã¡ã¢ã
Windowsã§ããã»ã¹èµ·åãçµäºå¶å¾¡ãè¡ããªãwin32-processã便å©ã
ãããããã¯ãã³ããããã³ã°ã¢ã¼ãããµãã¼ããã¦ããããçµäºç£è¦ã¡ã½ããwaitpid()ã¯ã¹ã¬ããããããã¯ãã¦ãã¾ããä¾ãã°DRbã®å é¨ã§ä½¿ãã¨ãèµ·åããããã»ã¹ãçµäºããã¾ã§DRbå ¨ä½ãå¿çããªããªããããã¯å°ãã
ããã§ãWin32APIãç´æ¥å¼ã³åºãã¦ããã»ã¹ãå¶å¾¡ãããã¨ã§åé¿ã
require 'rubygems' require 'win32/process' require 'windows/synchronize' require 'windows/process' require 'windows/handle' include Windows::Synchronize include Windows::Process include Windows::Handle #å¤é¨ããã»ã¹èµ·åã»çµäºå¾ ã¡ã¹ã¬ããã®ä½æ t = Thread.new do #init.sqlå SQLæã§ã®é·å¤§ãªå¦çãæ³å®ãï¼ãã¹ãæã¯notepad.exeçã§ä»£ç¨ï¼ pi = Process.create("app_name" => "sqlite3.exe -init init.sql test.db .q") #ããã»ã¹ç£è¦ãWin32APIã§è¡ã until WaitForSingleObject(pi.process_handle, 0) == WAIT_OBJECT_0 puts "waiting:(#{Time.now})" sleep 1 end #ããã»ã¹ãã³ãã«ãéãã CloseHandle(pi.process_handle) end t.join
ãããªãã°WIN32APIã«ããå¶å¾¡ã¨ãªãã®ã§ãã¹ã¬ããã¯ãããã¯ãããªãã
win32-processã®waitpidãWIN32APIã§å¾
ã¡ããã¦ããã®ã ããã©ãããã»ã¹çµäºç£è¦ã¢ã¼ãã使ã£ã¦ããããã«ã¹ã¬ããããããã¯ããã¦ãã¾ãããã§ãããæ¨æºã®waitpidã¨å¼æ°äºææ§ãä¿ã¦ãªãã®ã§ãããã¦ããããã®ããªï¼
ã¨ãããããã®æ¹æ³ã§åé¿ã§ããã®ã§ããã¨ããã
*1:ä»åã¯sqlite3.exeã使ããã¨ãã¦åµã£ã