[Win32utils-devel] [ win32utils-Support Requests-22149 ] open3 and daemon

noreply at rubyforge.org noreply at rubyforge.org
Fri Jan 10 15:47:30 UTC 2014


Support Requests item #22149, was opened at 2008-09-24 08: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: Daniel Berger (djberg96)
Date: 2014-01-10 08:47

Message:
Is this still an issue?

----------------------------------------------------------------------

Comment By: Florian Dütsch (der_flo)
Date: 2009-01-13 07:32

Message:
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

----------------------------------------------------------------------

Comment By: Daniel Berger (djberg96)
Date: 2009-01-03 12:59

Message:
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

----------------------------------------------------------------------

Comment By: Grzegorz Marszałek (graf0)
Date: 2008-12-29 06: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


More information about the win32utils-devel mailing list