Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

how to redirect STDERR and STDOUT to a file when running as a windows service?

by toadi (Chaplain)
on May 12, 2006 at 10:10 UTC ( [id://548938]=perlquestion: print w/replies, xml ) Need Help??

toadi has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have a perl script as a service in windows:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\daemon\Parameter +s] "Application"="C:\\perl\\bin\\perl.exe" "AppParameters"="c:\\server\\server.pl"

I installed it wit srvany.

Now I have a debug switch I can turn on and then all the print statements get printed. Also there are some issues throwing perl warnings. I tried to redirect with >> and 2>>, but this doesn't work while running as a service.

I tried to create a bat file, but then I can't stop the service anymore.

So I need some guidance how to redirect the STDERR AND STDOUT to a file when running as a windows service.



--
My opinions may have changed,
but not the fact that I am right

Edit: g0n - removed pre tags, added formatting

2006-05-13 Retitled by Arunbear
Original title: 'Cathing errors and print statements'

  • Comment on how to redirect STDERR and STDOUT to a file when running as a windows service?
  • Download Code

Replies are listed 'Best First'.
Re: how to redirect STDERR and STDOUT to a file when running as a windows service?
by wazoox (Prior) on May 12, 2006 at 11:35 UTC
    redirect your standard output and error by opening the log file , this way :
    open ( STDOUT, ">>$logfilename" ) or die "aargh... $!"; open ( STDERR, ">>$errorfilename" ) or die "aargh... $!";
    In case you'd rather use only one file, you could do :
    open ( STDERR , '>>$logfilename' ) or die "aaaagh... $!"; open ( STDOUT , ">&STDERR" ) or die "aaaagh... $!";
      Duh I should have known that :) Friday afternoon first sunny week and the brain leaves the building :D


      --
      My opinions may have changed,
      but not the fact that I am right

      Thanks, you save my day.
Re: how to redirect STDERR and STDOUT to a file when running as a windows service?
by Hue-Bond (Priest) on May 12, 2006 at 10:14 UTC
    I tried to redirect with >> and 2>>

    Instead of doing that, just pass a parameter to the script (eg: "-d") and then in the script, check the presence of that parameter (Getopt::Std, Getopt::Long) and open the necessary files.

    --
    David Serrano

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://548938]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-18 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found