Perl Forum for Beginners

Redirect STDERR

Nov 3, 2010 12:06 am
Bryan R Harris



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 die "$me: Couldn't open $outfile: $!\n";
$| = 1; # and don't buffer it
**************************************

I decided I want STDERR to also be redirected to the same outfile as STDOUT
instead of sending it to /dev/null. Is that possible?

TIA.

- Bryan

Nov 3, 2010 4:16 am
C.DeRykus
Re: redirect STDERR

On Nov 2, 5:06?pm, Bryan_R_Har...@raytheon.com (Bryan R Harris) wrote:
> 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 die "$me: ?Couldn't open $outfile: ?$!\n";
> $| = 1; ? ? ? ? # and don't buffer it
> **************************************
>
> I decided I want STDERR to also be redirected to the same outfile as STDOUT
> instead of sending it to /dev/null. ?Is that possible?
>

perldoc perlopentut and look for: Re-Opening Files (dups)

--
Charles DeRykus



Nov 4, 2010 12:43 pm
Bryan Harris
Re: redirect STDERR



Thank you!


> On Nov 2, 5:06=A0pm, Bryan_R_Har...@raytheon.com (Bryan R Harris) wrote:
>> I have these lines in my script:
>>=20
>> **************************************
>> for my $handle (*STDIN, *STDERR) {
>> =A0 =A0 open($handle, "+</dev/null") or die "$me: =A0Can't reopen $handle to
>> /dev/null: $!. =A0Exiting.\n";
>>=20
>> }
>>=20
>> # open outfile for further recording
>> open(STDOUT,">$outfile") or die "$me: =A0Couldn't open $outfile: =A0$!\n";
>> $| =3D 1; =A0 =A0 =A0 =A0 # and don't buffer it
>> **************************************
>>=20
>> I decided I want STDERR to also be redirected to the same outfile as STD=
OUT
>> instead of sending it to /dev/null. =A0Is that possible?
>>=20
>=20
> perldoc perlopentut and look for: Re-Opening Files (dups)
>=20
> --
> Charles DeRykus
>=20
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>=20
>=20






Previous Thread: Re: Subroutine question: Placement of subroutine definitions matter?
Next Thread: How to compare 2 elements in an array

Related Forum Topics
Redirecting STDERR with IO::Tee
I have a script which runs mostly via a cron job and sometimes interactively. I would like STDERR to automatically print to both the console and to a logfile simultaneously.

Right now I've gotten as far as merging both file handles with IO::Tee but I'm not sure if I'm heading down the right...
Can not mix output of STDERR and STDOUT
Hi experts
When I am using STDERR and STDOUT for mixed output, I found a problem.
Output of STDERR and STDOUT can not be mixed.
Here is the snippet.

#####################################
print STDOUT "This is STDOUT\n";
print STDERR "This is STDERR\n";
print STDOUT "This is...
How to print errors to both STDERR & a file?
I'd like to automatically have my script's errors and warnings sent to
both STDOUT (console) and a log file. What is the proper way of doing this?

Pablo


Redirecting STDOUT and STDERR for system()

Hello List,

as part of a Perl script of mine, I want to execute a program, get its
return code AND capture its output on both STDERR and STDOUT. I tried
IO::Handle, but that only gives me STDOUT and not the return code. Using
qr//, I cannot read linewise and have to load the complete...
How to catch error message instead of printing to stderr for rmtree
Hi

I want to use rmtree to delete a dir and use variables to catch the
error message. However, when i am about to delete a dir that does not
belong to me, it still print the error message to stderr. Does anyone
have clue?

my script: test.pl

use File::Path;
File::Path::rmtree(...
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--


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



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...
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