Skip to content

Instantly share code, notes, and snippets.

@dotandimet
Created August 21, 2011 07:29
Show Gist options
  • Save dotandimet/1160289 to your computer and use it in GitHub Desktop.
Save dotandimet/1160289 to your computer and use it in GitHub Desktop.
Trying to use FCGI and output capture together
#!/usr/bin/perl
use warnings;
use strict;
use CGI::Fast;
use Capture::Tiny qw(capture);
use IPC::Run3 qw(run3);
my $cmd = 'date';
my $fmt = '+%h%m';
while(my $q = CGI::Fast->new){
print $q->header('text/plain');
print "Hello!\n Trying Capture::Tiny:\n";
eval {
my ($out, $err) = capture {
0 == system($cmd, $fmt) || die $!;
};
print "\nCaptured output: $out\n";
print "\nCaptured stderr: $err\n";
};
if ($@) {
print "Died with error:\n$@\n";
}
print "Trying IPC::Run3:\n";
eval {
my ($out, $err);
run3([$cmd, $fmt], undef, \$out, \$err) || die "Failed: $!";
print "\nCaptured output: $out\n";
print "\nCaptured stderr: $err\n";
};
if ($@) {
print "Died with error:\n$@\n";
}
}
@dotandimet
Copy link
Author

Command Line output:
Content-Type: text/plain; charset=ISO-8859-1

Hello!
Trying Capture::Tiny:

Captured output: Aug08

Captured stderr:
Trying IPC::Run3:

Captured output: Aug08

Captured stderr:

@dotandimet
Copy link
Author

Browser output:
Hello!
Trying Capture::Tiny:
Died with error:
Not a GLOB reference at /evogrid/software/lib/perl5/site_perl/5.12.2/x86_64-linux/FCGI.pm line 125.

Trying IPC::Run3:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment