Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Why does IPC::System::Simple not capture output when Perl is running as CGI under IIS?

by matterofact (Initiate)
on Jul 10, 2013 at 15:36 UTC ( #1043495=perlquestion: print w/ replies, xml ) Need Help??
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?

Comment on Why does IPC::System::Simple not capture output when Perl is running as CGI under IIS?
Select or Download Code
Re: Why does IPC::System::Simple not capture output when Perl is running as CGI under IIS?
by daxim (Chaplain) 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

      So there's no way to work around this using IPC::System::Simple? Should I just revert back to using qx// and forget about it?

        So there's no way to work around this using IPC::System::Simple?

        I don't know.

        Should I just revert back to using qx// and forget about it?

        If qx// works, its probably because its creating a console  cmd /x /c ...your stuff here .. as in  C:\WINDOWS\system32\cmd.EXE

        So you might be able to persuade IPC::System::Simple to use the shell (cmd.exe) , but it kind of defeats the purpose of using IPC::System::Simple

        Or you might use Win32::ShellQuote like I showed to launch cmd.exe safely with qx{}

        Or you might make it work if you manage to use Win32::Console to allocate a console

        FWIW, I think the real problem is win32 webservers which spawn procs without an allocated console (IMHO dumb), but I haven't even seen this issue discussed anywhere

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1043495]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-29 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls