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

Wise ones, I have a dilemma.

Quick and dirty explaination: I need a way of splitting STDERR
in the same way that the /bin/tee command splits STDOUT.

I am using Net::FTP to login and retrieve a file from a VAN, (value added network). After retrieving data the VAN returns a line

Total bytes retrieved: 0        stored: 0
... I need to be able to "catch" this line in a logfile AND still have the messages send to STDERR.

I am using Debug => 1 when I call Net::FTP

use Net::FTP; $ftp = Net::FTP->new("servername", Debug => 1); $ftp->login("username","passwd"); $ftp->message(); $ftp->cwd("/tmp"); $ftp->get("some.file"); print "get returned: $ftp\n"; $ftp->quit;

So, the line that I mention above is returned to STDERR, just as perldoc.com documentation says. My problem is that I need to be able to BOTH, have this information printed to STDERR for my system to log it AND be able to capture this data in a separate logfile that my Operations group can monitor.

As you can see from the code above, I have tried using message(), inherited from Net::Cmd, and printing the value of $ftp. However, these options only print the Net::FTP=GLOB(0x226c14) value of the command, I need the text messages.

I have tried using filehandles and several other creative, but unsuccessful options.

I can easily redirect STDERR to a file, or allow STDERR to operate normally, but I have not been able to get BOTH to work. Please help if you can.

Edited: Fri Jun 21 15:12:08 2002 (GMT), by Footpad: Fixed broken </CODE> tag and modified HTML Formatting to improve XML compatibility.

Replies are listed 'Best First'.
Re: Splittig STDERR output to file AND STDERR
by broquaint (Abbot) on Jun 21, 2002 at 14:45 UTC
    Check out the IO::Tee module for all your filehandle multiplexing needs.
    HTH

    _________
    broquaint

      This works well when I want to send output to multiple locations.
      and thanks for that

      However, I've been trying different combinations of IO::Tee without
      success, the Net::FTP module is writing to STDERR, not my perl program.
      so IO::Tee isn't helping... unless I'm missing something. :-)

Re: Splittig STDERR output to file AND STDERR
by flounder99 (Friar) on Jun 21, 2002 at 14:58 UTC
      Filter is not exactly what I was looking for, but you're right!
      That is a very interesting module! I'll keep it in mind.

      Thanks!

Re: Splittig STDERR output to file AND STDERR
by grantm (Parson) on Jun 21, 2002 at 15:15 UTC

    I'm not entirely clear on where the message is generated, but your code includes this line:

    $ftp->message();

    Which gets the text of the last FTP protocol response from the server and then does nothing with it.

    Perhaps you should incorporate it into your print line:

    print "get returned: ", $ftp->message(), "\n";
      Sorry, that is a bit unclear.

      The $ftp->message(); line is one of the attempts that I've made
      to get the STDERR information returned to me.

      This line did indeed return data but only a GLOB(x234982395)
      string, which is not much use.

Re: Splittig STDERR output to file AND STDERR
by Anonymous Monk on Jun 22, 2002 at 03:13 UTC
    This is faq, so you ought to look it up there.
      Not that I see.

      I see how, and already am adept in, redirecting STDOUT and STDERR

      The Net::FTP module is sending it's debugging information to STDERR
      I need that information to go the STDERR but I also need that
      information to go to a file.
      Redirecting STDERR is not enough to satisfy this requirement.

      thanks for trying though.