Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Capture-Tiny CPAN distribution.

Report information
The Basics
Id: 62452
Status: resolved
Priority: 0/
Queue: Capture-Tiny

People
Owner: Nobody in particular
Requestors: dagolden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



CC: bug-Capture-Tiny [...] rt.cpan.org
Subject: Re: Problem with Capture::Tiny, system() and HTTP::Server::Simple::CGI
Date: Mon, 25 Oct 2010 23:06:11 -0400
To: Karl Gaissmaier <karl.gaissmaier [...] uni-ulm.de>
From: David Golden <dagolden [...] cpan.org>
Thank you very much for the report. I'll start looking into it. I suspect that the issues are related to HTTP::Server::Simple::CGI also munging file descriptors, but I'll give it a try. For reference, what is your perl -V output? On Mon, Oct 25, 2010 at 6:28 PM, Karl Gaissmaier <karl.gaissmaier@uni-ulm.de> wrote: Show quoted text
> Hi Mr. Golden, > > thanks a lot for your work for the perl community! > > I'm using your Capture::Tiny to catch STDOUT and STDERR from external > commands via system(). This works normally perfect, but within a > request_handler in HTTP::Server::Simple::CGI the capture doesn't work. > > I need this simple HTTP server for test suites, sorry. > > I shrinked the code to a few couple of lines, perhaps you can find > the edge case: > > #!/usr/bin/env perl > MyServer->new->run; > > package MyServer; > use base 'HTTP::Server::Simple::CGI'; > use Capture::Tiny qw(capture); > > sub handle_request { >    my ( $stdout, $stderr ) = capture { system('echo Hello World!') }; > >    print "HTTP/1.0 200 OK\r\n" >      . "Content-Type: text/html\r\n\r\n" >      . "<html><head></head><body>STDOUT: $stdout</body></html>"; > } > > After starting this script you should browse to localhost:8080 > > The output of system() is displayed on the screen instead getting captured > and send to the Web-client. > > Would be really great if you could find the edge case in > HTTP::Server::Simple or Capture::Tiny which prevents capturing. > > Best Regards >   Charly Gaissmaier >
Unfortunately, I think this isn't solveable. HTTP::Server::Simple::CGI localizes STDOUT and STDERR before handling the request. This effectively masks the system STDOUT/STDERR (on file descriptors 1 and 2). When capture() is called, it captures whatever is sent to the localized STDOUT and does not prevent the system from still sending to fd 1. HTTP::Server::Simple::CGI would need to reopen STDOUT as duplicates of handles and then restore them later instead of localizing. Sorry. I wish I could be more helpful. David