Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm having a problem capturing stderr using Capture::Tiny in a CGI script running in an Internet browser. I am using Capture-Tiny 0.36 and perl 5.8.8 on Linux.
=========== Background: ===========
I have a little javascript code which posts a form (a simple html report with a submit button) to a perl CGI script using a bit of AJAX (i.e. XMLHttpRequest)
Within the CGI script, I am using Capture::Tiny to extract stdout and stderr. The format of my CGI script is the following:
use Capture::Tiny ':all'; use CGI qw(:standard); my $params = $cgi->Vars(); my $obj = new Object($params); $obj->buildState; my ($stdout,$stderr,@results) = capture { $obj->doAction(); }; buildHtmlStatusOutput($stderr);
The details of Object are not really important (at least I don't think).
IMPORTANT: $obj->doAction() calls perl scripts (via system commands) to perform its action. These perl scripts use Log4perl to write its output to the console.
=========== Issue: ===========
Most of time, capturing the output of the underlying perl scripts works beautifully. Once in awhile, however, it doesn't work at all and stops after the capture. It just seems to die within the capture {} and NEVER calls buildHtmlStatusOutput
I've found an example of this that is consistently repeatable; however, I still cannot figure out why capture doesn't work
================== Interesting Point: ==================
As I was trying to figure out a solution, I noticed that the following code actually displays the desired output (only tee_merged works, tee does NOT), but unfortunately my buildHtmlStatusOutput() function isn't called (which kind of makes sense to me since we're teeing the output).
my ($output_merged,@results) = tee_merged { $obj->doAction(); };
Any suggestions would be very much appreciated. I have gotten so far with this project. I would hate this to be a showstopper.
Thank you very much for your time!
Best regards,
Michael
|
|---|