punkish, It seemed to work for me. I used sc to do the install. Here is the script I registered along with a transcript of what I did after the __END__:

use Win32::Daemon; # print LOG "hello\n"; BEGIN { open( STDERR, ">>myservicelog.err" ) or die "invisible error"; warn "$0 started ".localtime().$/; } open LOG, ">>mylogfile.txt" or die; # Start the service control loop Win32::Daemon::StartService(); while( SERVICE_STOPPED != ( $State = Win32::Daemon::State() ) ){ if( SERVICE_STARTING == $State ) { # some service startup code # ...... Win32::Daemon::State( SERVICE_RUNNING ); } elsif( SERVICE_PAUSE_PENDING == $State ) { Win32::Daemon::State( SERVICE_PAUSED ); next; } elsif( SERVICE_CONTINUE_PENDING == $State ) { Win32::Daemon::State( SERVICE_RUNNING ); next; } elsif( SERVICE_STOP_PENDING == $State ) { # some service shutdown code # ............ Win32::Daemon::State( SERVICE_STOPPED ); next; } elsif( SERVICE_CONTROL_SHUTDOWN == $State ) { # Request x seconds to shutdown... Win32::Daemon::State( SERVICE_STOP_PENDING, 45 ); # .............. Win32::Daemon::State( SERVICE_STOPPED ); next; } elsif( SERVICE_RUNNING == $State ) { doMyStuff(); print LOG "DONE!\n"; sleep 3; } else { # Un-handled control messages Win32::Daemon::State( SERVICE_RUNNING ); } sleep 5; } Win32::Daemon::StopService(); sub doMyStuff { print LOG "hello\n"; } __END__ c:\>sc create perlservice binPath= "c:\mtapps\perl\580\delta\bin\perl +c:\tmp\ntperlservice.pl" DisplayName= perlservice [SC] CreateService SUCCESS c:\>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 1077 (0x435) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>sc start perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 2 START_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x7d0 PID : 5348 FLAGS : C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 2 START_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x7d0 C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>cat c:\winnt\system32\myservicelog.err c:\tmp\ntperlservice.pl started Tue Dec 28 09:03:32 2004 C:\tmp>cat c:\winnt\system32\mylogfile.txt C:\tmp>sc stop perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 3 STOP_PENDING (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>sc query perlservice SERVICE_NAME: perlservice TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SH +UTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\tmp>cat c:\winnt\system32\mylogfile.txt hello DONE! hello DONE! hello DONE! hello ....

As I suspected, LOG is being buffered. So it didn't show up until after I stopped the service.

Hope this helps.


"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.


OSUnderdog

In reply to Re: Win32::Daemon installed service fails to start by osunderdog
in thread Win32::Daemon installed service fails to start by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.