Let me ask the obvious...
Does the service account have access to write and append to
d:\fred\betty\wilma\wilma.txt? Also make sure that the directory
d:\fred\betty\wilma already exists otherwise the open will fail.
You could try code like:
if( open( LOG, ">> $OutputPath" ) )
{
$OldStdOut = select( LOG );
# Disable buffering...
$| = 1;
}
print "If the output file was created then STDOUT now points to it\n";
close(LOG) if( fileno( LOG ) );
-----Original Message-----
From: Philip Morley [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 09, 2002 7:40 AM
To: [EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: Redirecting STDOUT with Win32::Daemon
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
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs