我目前擁有以下內容作爲Windows服務的「可執行文件路徑」。如何將Ruby/Rails Windows守護程序轉換爲可調試的應用程序?
我想了解如何將其轉換爲命令行應用程序,以便我可以交互式調試它。
Windows服務路徑爲可執行文件: 「C:\ LONG_PATH_1 \紅寶石\ BIN \ rubyXXXX_console.exe」 「C:\ LONGPATH_2 \ windows_script.rb」
windows_script.rb如下:
# console_windows.rb
#
# Windows-specific service code.
# redirect stdout/stderr to file, else Windows Services will crash on output
$stdout.reopen File.open(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..',
'log', 'XXXX_console.output')), 'a')
$stderr.reopen $stdout
$stdout.sync = true
$stderr.sync = true
require File.join(File.dirname(File.expand_path(__FILE__)),"script_helper.rb")
require 'rubygems'
require 'win32/daemon'
include Win32
class BackgroundWindowsDaemon < Daemon
def service_init
# Do startup in service_main so that Windows Services doesn't timeout during startup
end
def service_main
BackgroundScriptHelper.request_start
BackgroundScriptHelper.monitor
end
def service_stop
BackgroundScriptHelper.request_stop
end
end
BackgroundWindowsDaemon.new.mainloop
顯然,你可以在你的windows腳本中需要調試器gem,然後在你的方法中簡單地寫入「調試器」。如果代碼調用這種方法,它將停止代碼,你可以在普通的rails控制檯中進行調試。 – Mattherick 2013-05-06 11:11:37
Mattherick,謝謝!我是Rails/Ruby中的新手。你能提供具體步驟來做到這一點嗎? – chuacw 2013-05-06 12:21:16