matterofact has asked for the wisdom of the Perl Monks concerning the following question:
IIS 7.5 (Windows 7), Perl 5.16.3 (Strawberry Perl)
I'm trying to use IPC::System::Simple to run a command and capture the output, via either capture() or capturex() (they should both behave exactly the same under Windows). The Perl script is running as a web page under IIS, which has CGI handler mappings configured for Strawberry Perl. The problem is that the command runs and returns an exit value of 0, yet no output is captured. However, if I run the exact same code from a command prompt, it works fine. If I use IPC::System::Simple's system() replacement, output is printed, but not captured---it works fine. If I use backticks, it works fine.
Here are some examples to illustrate what's happening:
use strict; use warnings; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use IPC::System::Simple qw(capture system $EXITVAL); print "Content-Type: text/html\n\n"; my $results = capture('svn info <url> --non-interactive --trust-server +-cert --username <user> --password <pass> --config-dir <dir>'); print "<pre>Exit value: $EXITVAL\n\n$results</pre>";
Exit value is 0, but no results are printed. If I change capture() to system(), the results are printed to the browser, and the exit value is still 0:
system('svn info <url> --non-interactive --trust-server-cert --usernam +e <user> --password <pass> --config-dir <dir>');
If I modify the script to this:
use strict; use warnings; use IPC::System::Simple qw(capture system $EXITVAL); my $results = capture('svn info <url> --non-interactive --trust-server +-cert --username <user> --password <pass> --config-dir <dir>'); print $results;
And then I run it from the shell, I see all the glorious output of svn info.
If I instead use backticks or qx//, and then run the script through IIS and hit the page in a browser, the output is captured and printed just fine.
use strict; use warnings; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use IPC::System::Simple qw(capture system $EXITVAL); print "Content-Type: text/html\n\n"; my $results = `svn info <url> --non-interactive --trust-server-cert -- +username <user> --password <pass> --config-dir <dir>`; print "<pre>$results</pre>";
So, it looks like capture() is not capturing, but only when running through IIS. It's not a permissions problem, because backticks work. In fact, the command itself is working (exit value of 0, output seen via system()). It's just that the output is escaping / being redirected somewhere / not being captured.
Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why does IPC::System::Simple not capture output when Perl is running as CGI under IIS?
by daxim (Curate) on Jul 10, 2013 at 15:51 UTC | |
|
Re: Why does IPC::System::Simple not capture output when Perl is running as CGI under IIS? (console)
by Anonymous Monk on Jul 11, 2013 at 00:13 UTC | |
by matterofact (Initiate) on Jul 11, 2013 at 16:53 UTC | |
by Anonymous Monk on Jul 12, 2013 at 09:11 UTC |