I have been trying, unsuccessfully to redirect the STDOUT from my perl
script running as a service with Win32::Daemon.

The method I have been using is to open the STOUT handle to a file,
$FileName.  See the code example below.  Most of the service stuff has been
copied from David Roth's website, but the crux is in the main body, " print
"hello world\n"; " doesn't append anything to $FileName.

Any suggestions?

Phil Morley.

use Win32::Daemon;

my $FileName = "D:\\fred\\betty\\wilma\\wilma.txt";
open(STDOUT, ">>$FileName") || die;

Win32::Daemon::StartService();
while (SERVICE_STOPPED != (my $State = Win32::Daemon::State()))
{
  if (SERVICE_START_PENDING == $State)
  {
    Win32::Daemon::State(SERVICE_RUNNING);
    $PrevState = SERVICE_RUNNING;
  }
  elsif (SERVICE_STOP_PENDING == $State)
  {
    Win32::Daemon::State(SERVICE_STOPPED);
  }
  elsif (SERVICE_PAUSE_PENDING == $State)
  {
    Win32::Daemon::State(SERVICE_PAUSED);
    $PrevState = SERVICE_PAUSED;
    next;
  }
  elsif (SERVICE_CONTINUE_PENDING == $State)
  {
    Win32::Daemon::State(SERVICE_RUNNING);
    $PrevState = SERVICE_RUNNING;
    next;
  }
  elsif (SERVICE_STOP_PENDING == $State)
  {
    Win32::Daemon::State(SERVICE_STOPPED);
    $PrevState = SERVICE_STOPPED;
    next;
  }
  elsif (SERVICE_RUNNING == $State)
  {
    print  "hello world\n"; # doesn't work!
    if (SERVICE_CONTROL_NONE != (my $Message =
Win32::Daemon::QueryLastMessage(1)))
    {
      if (SERVICE_CONTROL_INTERROGATE == $Message)
      {
        Win32::Daemon::State($PrevState);
      }
      elsif(SERVICE_CONTROL_SHUTDOWN == $Message)
      {
        Win32::Daemon::State(SERVICE_STOP_PENDING, 25000);
      }
      else
      {
        Win32::Daemon::State($PrevState);
      }
    }
  }
} # end of while loop
Win32::Daemon::StopService();



_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to