From: Glen Holcomb Date: 2008-05-06T21:59:39+09:00 Subject: Re: Win32 Service Problem ------=_Part_20712_30753447.1210078775344 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks, I'll give it a shot. On Mon, May 5, 2008 at 6:47 PM, Daniel Berger wrote: > > > On May 5, 6:24 pm, "Glen Holcomb" wrote: > > I'm having an issue with Win32 Service > > > > I have a simple script that I want to run as a service however the > service > > won't start (timeout issue). I've tried several things but nothing I do > > seems to make any difference at all. > > > > Here is the code: > > > > begin > > require 'rubygems' > > require 'win32/service' > > require 'chronic' > > > > include Win32 > > > > class Daemon > > def service_init > > test_log = File.new("path_to_where_it_goes", "w") > > test_log.puts "got to init" > > test_log.close > > end > > > > def service_main > > while running? > > if Time.now < Chronic.parse('today 10:00pm') > > sleep(Chronic.parse('today 10:00pm') - Time.now) > > `shutdown /s /t:60` > > else > > sleep(Chronic.parse('tomorrow 10:00pm') - Time.now) > > `shutdown /s /t:60` > > end > > end > > end > > end > > rescue Exception > > logfile = File.new("path_to_logfile", "w") > > logfile.puts $! > > logfile.close > > end > > > > Daemon.mainloop > > > > I get absolutely no feedback from the script it's self. In the even log > it > > says the service didn't respond within 30 seconds. Oddly enough it > decides > > this after a second or two. I've tried the script with different code > in > > the service_init method and without a service_init method it doesn't > seem to > > make any difference. > > > > I realize this would be easier with a task but for reasons beyond my > control > > the task scheduler is turned off on all classroom and lab computers. > > There's no shell associated with a service, so doing backticks or > system commands in a service is a Bad Idea. Also, as of version 0.6.0 > STDIN, STDOUT and STDERR are redirected to NUL by default, so you'll > have to reopen STDERR to a log file if you want to see the full output > (what you saw there happened before they were redirected). > > My recommendation is not to use backticks but to use WMI + > Win32_OperatingSystem via OLE. You can find details at: > > http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx > > Regards, > > Dan > > -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_20712_30753447.1210078775344--