Igor, thanks for the tip!

A search of CPAN turned up IPC::Open3::Simple

Very cool... Very easy to use and exactly what I needed.

Separate callback subs for STDOUT and STDERR... just push anything fed to
them into an array...  When all done, if array size > 0, fire off an email
with the contents.  

Bingo! Works perfectly!  Thanks again....

-Dan 

-----Original Message-----
From: Igor Sutton [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 18, 2007 2:31 AM
To: Dan Fish
Cc: beginners@perl.org
Subject: Re: Capturing stdout and stderr without redirection

Hi Dan,

2007/1/18, Dan Fish <[EMAIL PROTECTED]>:
> I've got a perl wrapper that conditionally runs another perl program using
> system()
>
> Something like:
>
>
>
> If( some_condition_applies){
>
>     system("myperlscript.pl");
>
> }
>
>
>
> myperlscript.pl  will complete silently if everything runs right, but
> because it reads some data files and interfaces to a mySQL database, there
> are times when it may encounter unforeseen errors.
>
>
>
> IF there is any output from myperlscript.pl, I'd like to capture it and
send
> it off in an email.  The sending in an email part I can handle. and I
think
> I can probably redirect the output of myperlscript.pl to a file and read
> that,  but is there a better, more elegant way to capture any
stdout/stderr
> output WITHOUT having to redirect and read another file?


Why don't you encapsulate the myperlscript.pl code on a reusable
module, then just 'use' it? I'm supposing that both code was written
by you.

If you *really* needs that, you can use IPC::Open2 or IPC::Open3 (if
you also needs STDERR). From IPC::Open3 documentation (perldoc
IPC::Open3):

    my($wtr, $rdr, $err);
    $pid = open3($wtr, $rdr, $err,
                    'some cmd and args', 'optarg', ...);


HTH!

-- 
Igor Sutton Lopes <[EMAIL PROTECTED]>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to