So, Perl inherits the streams pointed to by STDIN, STDOUT and STDERR from the shell. If you need to re-connect them to other streams the way you did, you should first save a reference to the original filehandles in some variables beforehand, so that when you need to restore you can reinitialize them using these references saved. Otherwise, the streams are closed and you have no way to open them again until the end of your script.
Or, you can wrap the code needed to use custom STD* streams in a code block, and use "local" variable instead. This way, the original streams are just suppressed but not closed while in the code block, that will be restored when the local scope terminates.
I'll give you an example of the second approach because I think this is easier.
$number_clients++;
print("Creating client $number_clients\r");
I have been using the above to increment on the screen as the script increments throughout a while loop. What I would like to know is what is the trick to keep the last one on the screen without printing it again?
Ie
... (1 Reply)
as the title suggests, i need to print a user message to a log file and the screen using perl.
in unix i set up a function using 'tee' like so
function Display_Message
{
echo "$*" | tee -ai $LOGFILE
}
the following command then obviously displays to the screen and prints to a log... (6 Replies)
I have two text files, each of then only containing ONE line and NO carraige return or white space at the end...how do I echo both of these text files to the screen without putting an extra line? I want to do this from the command line.
file1.txt:
this is file1.txt 1
file2.txt:
this is... (4 Replies)
Hi,
I've been using the following commands in my automated scripts, to ensure that all text output is sent to a log file instead of to the screen:
exec 1>>$SCRIPT_LOG_FILE
exec 2>>$SCRIPT_LOG_FILE
However, I've now discovered that the system used for automating the script executions... (4 Replies)
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.logBut during script execution I would like the output come back again to screen, how to do that?
Thanks
Lucas (4 Replies)
I have to redirect STDERR messages both to screen and also capture the same in a file but STDOUT only to the same file.
I have searched in this formum for a solution, but something like
srcipt 3>&1 >&2 2>&3 3>&- | tee errs
doesn't work for me...
Has anyone an idea??? (18 Replies)
I am having a problem figuring out how to turn stdout on in the middle of my ssh session. If I turn it on or off in the initial session it works, but if I try to turn it on in the middle, I can't seem to find the correct statement.
my $ssh = Net::SSH::Expect->new (
host =>... (1 Reply)
Hi,
I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed.
Below is my sample... (14 Replies)
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
Code:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.log
But during script execution I would like the output come back again to screen, how to do that?
Thanks
Luc
edit by bakunin: please use CODE-tags like the... (6 Replies)
Discussion started by: tmonk1
6 Replies
LEARN ABOUT DEBIAN
email::send::io
Email::Send::IO(3pm) User Contributed Perl Documentation Email::Send::IO(3pm)NAME
Email::Send::IO - Send messages using IO operations
SYNOPSIS
use Email::Send;
my $mailer = Email::Send->new({mailer => 'IO'});
$mailer->send($message); # To STDERR
$mailer->mailer_args('filename.txt');
$mailer->send($message); # write file
DESCRIPTION
This is a mailer for "Email::Send" that will send a message using IO operations. By default it sends mail to STDERR, very useful for debug-
ging. The IO functionality is built upon "IO::All". Any additional arguments passed to "send" will be used as arguments to "IO::All::io".
You can globally change where IO is sent by modifying the @Email::Send::IO::IO package variable.
@Email::Send::IO::IO = ('-'); # always append to STDOUT.
Examples
Sending to STDOUT.
send IO => $message, '-';
Send to a socket.
send IO => $message, 'server:1337';
SEE ALSO
Email::Send, IO::All, perl.
AUTHOR
Current maintainer: Ricardo SIGNES, <rjbs@cpan.org>.
Original author: Casey West, <casey@geeknest.com>.
COPYRIGHT
Copyright (c) 2005 Casey West. All rights reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
perl v5.8.8 2007-07-29 Email::Send::IO(3pm)