Perl Forum for Beginners

How to redirect a message simultaneously to a file-handler and standard O/P

Nov 17, 2009 5:32 pm
Jim Gibson

On 11/17/09 Tue Nov 17, 2009 9:24 AM, "Parag Kalra" <paragkalra@gmail.com>
scribbled:

> Hi All,
>
> I know this may be a very basic question but I don't know how to accomplish
> it. :(
>
> I want to know how to redirect a message simultaneously to a file-handler
> and standard O/P.
>
> So basically I want a short cut way to execute following 2 commands using
> one singe command which will print the message both into file handler and on
> the console:
>
> print $message;
> print FILE, $message;

You write a subroutine:

my_print
{
print "@_";
print FILE "@_";
}

and call it:

my_print($message);

You may want to choose a different way of treating multiple arguments.

You are looking here for what is sometimes called a "logger". There are Perl
modules on CPAN that may be of interest, such as Log::Dispatch or
Log::Log4Perl. Search the Log hierarchy for more. (I haven't used any of
them, so can't recommend any particular one.)

Nov 17, 2009 5:24 pm
Parag Kalra
How to redirect a message simultaneously to a file-handler and standard O/P

--0016e64b99f48f1e590478946599
Content-Type: text/plain; charset=UTF-8

Hi All,

I know this may be a very basic question but I don't know how to accomplish
it. :(

I want to know how to redirect a message simultaneously to a file-handler
and standard O/P.

So basically I want a short cut way to execute following 2 commands using
one singe command which will print the message both into file handler and on
the console:

print $message;
print FILE, $message;

Cheers,
Parag

--0016e64b99f48f1e590478946599--


Nov 17, 2009 7:46 pm
Matt
Re: How to redirect a message simultaneously to a file-handler and standard O/P

On Nov 17, 12:32?pm, jimsgib...@gmail.com (Jim Gibson) wrote:
> On 11/17/09 Tue ?Nov 17, 2009 ?9:24 AM, "Parag Kalra" <paragka...@gmail.com>
> scribbled:
>
> > Hi All,
>
> > I know this may be a very basic question but I don't know how to accomplish
> > it. :(
>
> > I want to know how to redirect a message simultaneously to a file-handler
> > and standard O/P.
>
> > So basically I want a short cut way to execute following 2 commands using
> > one singe command which will print the message both into file handler and on
> > the console:
>
> > print $message;
> > print FILE, $message;
>
> You write a subroutine:
>
> ? ? my_print
> ? ? {
> ? ? ? ? print "@_";
> ? ? ? ? print FILE "@_";
> ? ? }
>
> and call it:
>
> ? ? my_print($message);
>
> You may want to choose a different way of treating multiple arguments.
>
> You are looking here for what is sometimes called a "logger". There are Perl
> modules on CPAN that may be of interest, such as Log::Dispatch or
> Log::Log4Perl. Search the Log hierarchy for more. (I haven't used any of
> them, so can't recommend any particular one.)

http://search.cpan.org/~dagolden/Tee-0.13/lib/Tee.pod





Previous Thread: How to complete the loop while debugging.
Next Thread: Is it necessary to open the file again to read its contents.

Related Forum Topics
Redirect Find::File to /dev/null
I'm using Find::File in my program. Unfortunately I get the ugly
'Permission denied' output that I'd normally redirect to /dev/null if
I was using bash.

Here is the command I used to generate the Find::File code:
$ find2perl /usr -name libaest.dylib -print

I saved that to a new file and...
What's a database handler
Hi,

When I get a database handler with DBI,

my $dbh = DBI->connect(...);

Then I fork in the script:

my $pid = fork;
if ($pid ) { # parent
do something;
} else { # child
do something another;
$dbh->disconnect;
}

What I want to know is, when $dbh get disconnected in...
Text-html from file to a message body
HI Folk,

May I introduce myself, John Plumridge, London, UK.
- I'm still in awe of this whole creation we're in.

Nice to meet you.


I have a reason of course, for approaching you, via my MTNews 'console'.
What a great application!

MY problem is obtaining and passing...
RE: Non standard entity conversion
Hi List,

I am doing entity conversion decimal entity (input xml) 2 named
entity(output xml) in perl using HTML::Entities::Numbered. But it's not
returning named entity for some decimal entities. If any body have idea to
avoid the below issue, please share with me.


Ex: Coding.
use...
LWP module part of the standard distribution ?
I wonder if the LWP module is part of the standard distribution of Perl or not ? According the list provided by Module::CoreList it isn't (tested versions 5.006, 5.008 and 5.010), but it seems that it is widely spread nevertheless.

Can I rely upon LWP.pm being available on all web server (CGI)...
Mechanize Redirect
Have seen this issue addressed on this board in the past, but can't
figure out exactly what I need to do.

I'm using WWW::Mechanize and a webpage seems to be redirecting me but
Mechanize doesn't seem to follow it. I've heard to "Add the header
'Accept: text/html'" but alas I don't know how...
Redirect option
------=_Part_44916_7283763.1224155953729
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Is there any option to redirect a URL in perl other than Location ?

Regards

Sheela

------=_Part_44916_7283763.1224155953729--


Redirect STDERR


I have these lines in my script:

**************************************
for my $handle (*STDIN, *STDERR) {
open($handle, "+</dev/null") or die "$me: Can't reopen $handle to
/dev/null: $!. Exiting.\n";
}

# open outfile for further recording
open(STDOUT,">$outfile") or...
How to do absolute redirect in perl
$Request->redirect( url => $Std->url("/gp/errors/404"),type =>
"permanent");
works for me
but
$Request->redirect( url => $Std->url("http://www.google.com",
{absolute => 1});
does not work someone please help



How to redirect in system command two devices at once
Hello,

I am calling system() to run a devenv.exe to build vs 2005 solution
file.
My problem is I want to capture the output while building the solution
to a file and show the output to monitor at once.

Is there a way or a module to achieve that goal?

TIA