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

Dear monks,

My threaded Perl program is included in the run level scripts. The full path of the program is mentioned like so in /etc/rc3.d/SXXnetmon :

/usr/local/sbin/authdev.pl &

The threaded Perl program redirects all STDOUT and STDIN to a log file with these commands:

# Opening log file. # Redirecting OUTPUT and ERR to log file for all threads open OUTPUT, '>>', "/usr/local/xxx/log/lease.log" or die $!; open ERROR, '>>', "/usr/local/xxx/log/lease.log" or die $!; STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; STDERR->fdopen( \*ERROR, 'w' ) or die $!;

My question is:

  • Are STDOUT and STDERR defined for the program when the scripts are started using run-levels.

  • Replies are listed 'Best First'.
    Re: System runlevel scripts and STDOUT
    by Illuminatus (Curate) on Oct 13, 2010 at 14:37 UTC
      How would the program know it is being started as a 'runlevel script'? The filehandles STDOUT and STDERR are always defined. They may or may not be writing to anything readable by default. For example, if you run myscript.pl <args> > /dev/null 2>&1 (from a *nix environment), then STDOUT and STDERR are both writing to nothing. Your script should be fine re-opening them in the fashion you are demonstrating

      Given that, since this is a script being run as part of system startup, you do need to make sure that it is run after all scripts that initialize OS services/features that the script relies on.

      fnord

    Re: System runlevel scripts and STDOUT
    by hbm (Hermit) on Oct 13, 2010 at 15:17 UTC

      It is the tty that is not defined. The standard filehandles are defined, but not tied to a terminal.