It is currently Tue, 07 Dec 2021 02:58:45 GMT



 
Author Message
 redirecting stdio/err many times to many places
I'm in need of some code that will handle the redirection
of stdio many times to many places.  I'm a perl programmer
and am unable to accomplish this within perl.  Something
strange about cloning stdout the closing and opening it
many diferent times to many different places.  So I figure
I'll need to slug it out down at the system level.  
Working on Sun Solaris 7, compiling with gcc 3.0

Not interest in pc software.

I'm a working stiff, not a student looking for an easy out
for an assignment.



 Sat, 28 Feb 2004 02:57:55 GMT   
 redirecting stdio/err many times to many places

#! /usr/bin/perl -w
use strict;
open XXX, ">&STDOUT" || die "dup of STDOUT failed: %!\n";
print XXX "this is from XXX\n";
print STDOUT "this is from STDOUT\n";

However, see

http://www.perldoc.com/perl5.6/pod/perlopentut.html#Re-Opening-Files-...)



 Sat, 28 Feb 2004 03:15:39 GMT   
 redirecting stdio/err many times to many places
In article <3B9D0D33.761ED...@dal.asp.ti.com>,
Billy Patton  <bpat...@dal.asp.ti.com> wrote:

In Perl,

open(SAVED_STDOUT, ">&STDOUT");
open(STDOUT, ">somefile");
...
open(STDOUT, ">&SAVED_STDOUT");

is the way to redirect stdout to a file and then later direct it back to
where it originally went.  I don't think there's any reason why this
wouldn't work if you did it many times; if it doesn't work for you, try
posting in comp.lang.perl.

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Sat, 28 Feb 2004 03:17:33 GMT   
 redirecting stdio/err many times to many places

Doesn't work, when I close XXX and try it again STDOUT no longer
prints to screen.  What you have sent works perfectly for one time.
But I have to do it now 32 times and that will increase.



 Sat, 28 Feb 2004 03:30:07 GMT   
 redirecting stdio/err many times to many places

I don't know what the problem is. On my system

#! /usr/bin/perl -w
use strict;
open XXX, ">&STDOUT" || die "dup of STDOUT failed: %!\n";
open YYY, ">&STDOUT" || die "dup of STDOUT failed: %!\n";
open ZZZ, ">&STDOUT" || die "dup of STDOUT failed: %!\n";

print XXX "this is from XXX\n";
print YYY "this is from YYY\n";
print ZZZ "this is from ZZZ\n";
print STDOUT "this is from STDOUT\n";

produces the following output:

this is from XXX
this is from YYY
this is from ZZZ
this is from STDOUT

$ perl --version
This is perl, v5.6.0 built for i386-linux



 Sat, 28 Feb 2004 03:56:33 GMT   
 redirecting stdio/err many times to many places

Sorry, I'm trying to do too many things at once and didn't read that
carefully enough. Barry's response is the correct one.



 Sat, 28 Feb 2004 04:01:04 GMT   
 redirecting stdio/err many times to many places
Sorry I didn't explain my self fully the first time.
I need not only to divert STDOUT to file but also to screen.
Engineers have this crazy idea that program needs to tell them
something wile it's working! Go Figure!
Here my perl

&a;
&b;
&c;
&d;

sub a {
 open MY_COPY , ">&STDOUT"; # STDOUT dupped
 open TEE , "|tee a.stdout";
 open MY_COPY , ">&TEE";
 # do some writing and dia-an-dat
 close MY_COPY;
 close TEE;

sub b {
 open MY_COPY , ">&STDOUT"; # STDOUT dupped
 open TEE , "|tee b.stdout";
 open MY_COPY , ">&TEE";
 # do some writing and dia-an-dat
 close MY_COPY;
 close TEE;

ditto for c and d

My copy closes STDOUT.  Each line that I write, after a, will be
duplicated into the (b,c,d).stdout and nothing comes to screen.
ALso control does not return to tty. I have to ^C to exit program.

If I don't close MY_COPY and TEE the perl will automatically do it
for me.  Naming each one unique and not closing them would soon
hit the deafult Solaris limit for 64 filehandles opened at the
same time. (limits wil show you your defaults)



 Mon, 01 Mar 2004 02:44:09 GMT   
 redirecting stdio/err many times to many places
In article <3B9FACF9.7E6BD...@dal.asp.ti.com>,
Billy Patton  <bpat...@dal.asp.ti.com> wrote:

Why do you need MY_COPY?  Why not just open TEE, and do all your writing to
that?

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Mon, 01 Mar 2004 04:01:18 GMT   
 
   [ 8 post ] 

Similar Threads

1. .redirect not redirecting to some places

2. problem with redirecting stdio

3. Redirecting stdio

4. Can csh redirect stdio and stderr separately?

5. Using nohup and redirecting stdio

6. Redirecting stdio within a for loop

7. Redirecting stdio and stderr when using execvp

8. redirecting sys out and err to different files?

9. redirecting stdout/in/err on fork()

10. err redirect and log format


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software