[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] switching output from STDOUT to mail



On Tue, 25 Jun 1996, John Springer wrote:

> I'm trying to make a program that works in two modes: demo and !demo.
> 
> If it's !demo, I want to open a pipe to mail and print stuff to mail.
> If it's demo, I want to open to std out and print there (HTML, actually).
> This is a stupid form-mail program that I have grossly overcomplicated.
> Sorry about that.
> 
> 
> I've done:
> print "<HTML><BODY>Some Stuff";
> 
> if(!$demo){
>       open (MAIL,"| $mailprog.....);
>       &Print_Mail;
> }
> if($demo){
>       print "<PRE>;
>       open (MAIL,"| &2");

What you need to do is dup (create a duplicate) STDOUT with a statement like:

        open(MAIL, ">&STDOUT");

(BTW, '|' is for piping to programs not files or file handles.  So, ">&1" 
might work as well.)


>               #or >>&1 or |>>&1 and everything else I can thing of
>       &Print_Mail;
>       close(MAIL);
>       print </PRE>;
> }
> 
> sub Print_Mail()
>       print MAIL "lines of data\n";
> }
> What seems to happen is that the output for the regular print statements is
> spooled, and when I open MAIL for output it comes out ahead of all my HTML.
> 
> How can I correctly switch the print MAIL output so it streams with the
> output from the other print statements??
> 
> tia
> John.
> 
> --John Springer
>  _______________________________________________________________________
>  |        Can you use a creative, Internet-savvy marketing guy?        |
>  |      Check Me Out at <http://www.scruznet.com/~springer/HireMe>     |
>  |                                                                     |
>  | [This Space Paid For by the California Employment Development Dept] |
>  |_____________________________________________________________________|
> 
> 

John Peterson -- University Networking Services -- Brigham Young University
Internet: John_Peterson@byu.edu                       Phone: (801) 378-5007