I am attempting to use Win32::daemon to create a windows service. To start off easy, i installed a windows service using the code found on the html documentation for Win32::daemon.
use Win32::Daemon; %Hash = ( name => 'PerlTest', display => 'Oh my GOD, Perl is a service!', path => 'c:\perl\bin\perl.exe', user => '', pwd => '', parameters =>'c:\perl\scripts\service.pl', ); if( Win32::Daemon::CreateService( \%Hash ) ) { print "Successfully added.\n"; } else { print "Failed to add service: " . Win32::FormatMessage( Win32: +:Daemon::GetLastError() ) . "\n"; }
This installed the service fine with no errors. Then I tried to use the example service code:
use Win32::Daemon; # Tell the OS to start processing the service... Win32::Daemon::StartService(); # Wait until the service manager is ready for us to continue... while( SERVICE_START_PENDING != Win32::Daemon::State() ) { sleep( 1 ); } # Now let the service manager know that we are running... Win32::Daemon::State( SERVICE_RUNNING ); # Okay, go ahead and process stuff... open (OUT, ">>C:\perl\scripts\out.txt"); print OUT "Hello, World!"; close OUT; # Tell the OS that the service is terminating... Win32::Daemon::StopService();
But I am getting an error saying that the service started and stopped, and the file is not being opened. Please Help!

In reply to Win32::daemon and Perl by becca23

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.