Support Requests: Browse | Submit New | Admin
open3 blocks in combination with a daemon. here is the example-code: ################################################################################ require 'win32/open3' require 'win32/daemon' include Win32 ################################################################################ COMPUTER_NAME = 'test' LOGFILE = 'C:\test.txt' PSLOGGEDON_EXE = 'D:\pstools\psloggedon.exe' ################################################################################ class Daemon def service_main while running? # User ermitteln users = [] i, o, e = Open3.popen3("#{PSLOGGEDON_EXE} -l \\\\#{COMPUTER_NAME}") i.close e.close o.readlines.each do |line| m = /^DOMAINNAME\\(.*)$/.match line users << m[1] if m end o.close txt = "#{Time.new.strftime('%d.%m.%Y %H:%M')} - #{users.join(',')}" File.open(LOGFILE, 'a') { |file| file.puts txt } sleep 1 * 60 end end def service_stop exit! end end ################################################################################ Daemon.mainloop ################################################################################ The service/daemon looks for logged in users on a specific host and logs it to a file. The tool psloggedon (http://technet.microsoft.com/de-de/sysinternals/bb897545.aspx ) When not using a service and calling the open3-stuff directly everything is ok. But when starting as a service the psloggedon.exe does not exit. I don't know why and debugging is quite hard. Any ideas? Thanks, der flo
Add A Comment:
Date: 2009-01-13 14:32 Sender: Florian Dütsch Thanks for your answers! But look at the code, I don't use STDIN, STDOUT and STDERR. Nevertheless I will do a test with redirected output. Ciao, der Flo
Date: 2009-01-03 19:59 Sender: Daniel Berger That's probably why. If you redirect them to a non-tty device (say, a file) prior to starting the daemon, that may help. Remember, there's no tty associated with a service (normally, anyway). Regards, Dan
Date: 2008-12-29 13:23 Sender: Grzegorz Marszałek Hello! Maybe problem is that STDIN, STDOUT and STDERR are redirected to NULL when your code runs as service? Just guessing...