> > The example I quoted will do both, providing that you are
> > using the print command.
> >
> > How does your script normally output to STDERR?  Does it use the warn
> > command?  If so would it not be too much effort to change:
> >
> > warn "This is an error\n";
> >
> > to
> >
> > print $tee "This is an error\n";
> >
> > Regards,
> >
> > Phil Morley
>
> My script FTPs a file from a remote machine, using NET::FTP. I turn hash
> mark printing on, so that the operator can look at the window and see if the
> script is still working, or if the connection has died. i.e. if they see no
> new hash marks appearing after a few moments, they know it's died, and can
> kill and restart the script (after fixing the connection [which is extremely
> unreliable {and in a lab}]).
>
> When I set up the FTP connection, I set the debug level to 1, which results
> in copies of all commands and responses also being sent to STDERR. There are
> only 2 levels, 1 and 0.
>
> As soon as I do this:
> open (STDERR, "> err.txt") or die "can't redirect STDERR: $!\n";
>
> I lose all the "stuff" that was printed out to the screen, in particular the
> hash marks. Now, if the ftp was getting a particularly huge file, then how
> long does the operator wait around to see if the script is still running?
>
> So, my dilemma is that I want to log STDERR to a file, but I also need to
> have it echoed to the screen.
>
> I can EASILY print to the log file and screen, by using:
>
> print STDERR "Starting FTP..."; # This goes into err.txt
> print "Starting FTP..."; # This goes to the screen
>

You might try opening a file to STDERR and then fork a process
that effectively does "tail -f <file>", i.e. so that the forked code
is reading the file that you are writing to STDERR and writing to STDOUT.
There is no "tail" command that you can use but you should be able to
open STDERR to a pipe and the program on the other end of the pipe
programmatically does the "tee" function for you. There's no particular
reason why the program acting as a pipe couldn't be another perl script.

An alternative, if you get desperate, is to patch up your  own version of
the FTP module that uses IO::Tee and writes its output to an IO::Tee
object instead of STDERR;

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to