noreply at rubyforge.org
2008-Dec-29 13:23 UTC
[Win32utils-devel] [ win32utils-Support Requests-22149 ] open3 and daemon
Support Requests item #22149, was opened at 2008-09-24 15:18 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=412&aid=22149&group_id=85 Category: win32-service Group: None Status: Open Resolution: None Priority: 3 Submitted By: Florian D?tsch (der_flo) Assigned to: Nobody (None) Summary: open3 and daemon Initial Comment: 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 ---------------------------------------------------------------------- Comment By: Grzegorz Marsza?ek (graf0) Date: 2008-12-29 13:23 Message: Hello! Maybe problem is that STDIN, STDOUT and STDERR are redirected to NULL when your code runs as service? Just guessing... ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=412&aid=22149&group_id=85