Created
August 21, 2011 07:29
-
-
Save dotandimet/1160289 to your computer and use it in GitHub Desktop.
Trying to use FCGI and output capture together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; | |
} | |
} |
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
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: