Support Requests: Browse | Submit New | Admin

[#22149] open3 and daemon

Date:
2008-09-24 15:18
Priority:
3
Submitted By:
Florian Dütsch (der_flo)
Assigned To:
Nobody (None)
Category:
win32-service
State:
Closed
Summary:
open3 and daemon

Detailed description
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: Notepad

Please login


Followup

Message
Date: 2014-01-15 02:14
Sender: Daniel Berger

I'm going to close this as I suspect it's not an issue. It's
also probably better to use WMI to get that information anyway
instead of using open3.
Date: 2014-01-10 15:47
Sender: Daniel Berger

Is this still an issue?
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...

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
close_date2014-01-15 02:142014-01-15 02:14djberg96
resolution_idNone2014-01-15 02:14djberg96
status_idOpen2014-01-15 02:14djberg96