I´m currently using IIS7 to run a perl cgi script which calls a ".exe" file. My others perl cgi files work properly under my IIS configuration and this particular file is working fine on the command line mode. Actually when I run this file from my cgi, I
can see the process of the Task Manager but it just doesn´t stop as it should and my cgi also doesn´t deliver a complete set of HTTP headers (error 502.2 when I manually shut the process down or after the cgi timeout).
I basically try a lot of different IIS configurations such as enable Load User profil, allowing net.tcp , editing the file permission and everything I found.
Unfortunetly, the informations provided on your link were not so helpfull. The first line of my perl script is already as you show me.
Basically it looks like if the executable called by my perl is blocked in the middle of its execution and then it avoid the perl script to continue and finish the http headers set. I only got the 502.2 error if I manually kill the process or wait to cgi
timeout.
I can already assume that it´s not a .exe compilation error or a misfunction of my perl script cause everything is working well on the command line.
Maybe it´s a kind of IIS restriction which avoid the executable to end running....
Another thing that you might know: I´m creating a new IO::socket in my perl with this configuration
sub new {
my ($class, $prefix) = @_;
my $self = {};
bless $self, $class;
$self->{'prefix'} = $prefix;
$self->{'consoleSocket'} = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => '8081',
Proto => 'tcp',
);
return $self;
Of course I enabled the net.tcp on my web site but I may have also miss something here ;)
then here is the code in c++ to compile the executable
#ifdef WINCONSOLE
#include <iostream>
int main(int argc, char *argv[])
#else
#error Console only program
#endif
{
char c= 0;
while ( ! std::cin.eof() )
{
c = ( std::cin.get()) & 0xff;
if ( c == 'e' ) c='E';
else if ( c == 'E' ) c='e';
std::cout << c;
if ( c == 'q' || c=='Q' ) break;
}
return 0;
}
So this soft with the same behavior run also on the command line and show the same behavior on IIS. Maybe it can enlight you about the issue i experienced.
Anyway the bug is quite tricky, I made it run on apache and also to the command line but still no improvement under IIS...
Always the same kind of warning which I think prevent the ".exe" to end :Can't call method "close" on an undefined value at C:/Perl/lib/IPC/Open3.pm line 370. And of course no such warning under apache or command line :´(
Rom9854
7 Posts
Issue using perl cgi calling a .exe file
Feb 25, 2011 12:53 PM|LINK
Hello,
I´m currently using IIS7 to run a perl cgi script which calls a ".exe" file. My others perl cgi files work properly under my IIS configuration and this particular file is working fine on the command line mode. Actually when I run this file from my cgi, I can see the process of the Task Manager but it just doesn´t stop as it should and my cgi also doesn´t deliver a complete set of HTTP headers (error 502.2 when I manually shut the process down or after the cgi timeout).
I basically try a lot of different IIS configurations such as enable Load User profil, allowing net.tcp , editing the file permission and everything I found.
Does someone already experienced such an issue?
Thanks.
Romain
HCamper
8048 Posts
Re: Issue using perl cgi calling a .exe file
Feb 25, 2011 03:28 PM|LINK
Hello,
Could you look at this post in the IIS Net Forum http://forums.iis.net/p/1165965/1968207.aspx#1968207
guide for perl set-up using active state perl engine?
If you follow the steps it may fix your problems.
Try this in your scripts it must be the first line #!/usr/bin/perl -w .
For this issue "doesn´t deliver a complete set of HTTP headers error 502.2"
The problem with perl is when the Engine gets its first script command.
Thank You,
Cheers
Martin :)
Community Member Award 2011
Rom9854
7 Posts
Re: Issue using perl cgi calling a .exe file
Feb 28, 2011 08:19 AM|LINK
Thank you for your quick answer,
Unfortunetly, the informations provided on your link were not so helpfull. The first line of my perl script is already as you show me.
Basically it looks like if the executable called by my perl is blocked in the middle of its execution and then it avoid the perl script to continue and finish the http headers set. I only got the 502.2 error if I manually kill the process or wait to cgi timeout.
I can already assume that it´s not a .exe compilation error or a misfunction of my perl script cause everything is working well on the command line.
Maybe it´s a kind of IIS restriction which avoid the executable to end running....
Another thing that you might know: I´m creating a new IO::socket in my perl with this configuration
sub new {
my ($class, $prefix) = @_;
my $self = {};
bless $self, $class;
$self->{'prefix'} = $prefix;
$self->{'consoleSocket'} = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => '8081',
Proto => 'tcp',
);
return $self;
Of course I enabled the net.tcp on my web site but I may have also miss something here ;)
HCamper
8048 Posts
Re: Issue using perl cgi calling a .exe file
Feb 28, 2011 04:55 PM|LINK
Hello,
General note for command line code when you run code it is using your permissions and not those set at the Web Server.
The error 502.2 is Bad gateway. Which is from the Server status sub status list here http://support.microsoft.com/kb/943891 .
The error would make sense for these cases:
A) if user executing the code has limitied permissions to execute the code or use networking.
B) The information for the address or port are incorrect or not accessible.
C) One possible resolution is add the Network Service to allowed accounts in the location for where the code is located.
D) Change the time of execution for the CGI process here http://support.microsoft.com/kb/942059
Thank You,
Martin
Community Member Award 2011
Rom9854
7 Posts
Re: Issue using perl cgi calling a .exe file
Mar 01, 2011 08:01 AM|LINK
Yes this is also not helping,
I made a small software with the same behavior maybe it could help to solve the issue.
This is the perl code calling the .exe into a pipe via open2, it changes case of all e-characters on STDIN and printf to STDOUT, stops on q.
use strict;
use IPC::Open2;
use POSIX ":sys_wait_h";
$|=1;
my $in;
my $out;
my $filter = "demo.exe";
my $pid = open2($out, $in, $filter);
$|=1;
print "Content-Type:text/html\n\n";
print "<html><body>\n";
print "PID: $pid In: $in Out: $out\n";
print "In: Whatever\n";
print $in "Whatever\n";
#getIO($out);
print "In: Q\n";
print $in "Q\n";
getIO($out);
close($in);
close($out);
print "Waitpid\n";
waitpid($pid, &WNOHANG);
print "done\n";
print "</body></html>\n";
exit(0);
sub getIO
{
my $fh = shift;
my $data = '';
print "Out: ";
while ( !eof($fh) )
{
printf ("%s", getc($fh) );
}
print "\nOutput done\n";
}
then here is the code in c++ to compile the executable
#ifdef WINCONSOLE
#include <iostream>
int main(int argc, char *argv[])
#else
#error Console only program
#endif
{
char c= 0;
while ( ! std::cin.eof() )
{
c = ( std::cin.get()) & 0xff;
if ( c == 'e' ) c='E';
else if ( c == 'E' ) c='e';
std::cout << c;
if ( c == 'q' || c=='Q' ) break;
}
return 0;
}
So this soft with the same behavior run also on the command line and show the same behavior on IIS. Maybe it can enlight you about the issue i experienced.
Rom9854
7 Posts
Re: Issue using perl cgi calling a .exe file
Mar 03, 2011 10:28 AM|LINK
I also try to give all rights to the specific folder but it remains the same.
Is the probleme coming for trying to open a pipe to an executable under IIS?
HCamper
8048 Posts
Re: Issue using perl cgi calling a .exe file
Mar 07, 2011 11:04 AM|LINK
Hello,
The problem is with coding at the open2 library is throwing an error
always at this point:
my $pid = open2($out, $in, $filter);
I found where the block was by creating a dump of the execution and then use IIS Diag Trace.
The error has been a combination of required values with not finding the perl librarys location.
I tested on Active State Perl version 5.8 / Linux version 5.8 with code errors.
Thank You,
Martin
Community Member Award 2011
Rom9854
7 Posts
Re: Issue using perl cgi calling a .exe file
Mar 08, 2011 08:06 AM|LINK
Ok thank you for finding the issue, but do you know what I can try to fix it?
Is it just impossible to use open2 on IIS?
Thanks again
Romain
HCamper
8048 Posts
Re: Issue using perl cgi calling a .exe file
Mar 08, 2011 08:35 AM|LINK
Hello,
I do not have a fix but suggestions.
Get a simple example like file R/W sample that use Open2 that the library is used fully.
Set-up an enviornmental variable that points to the Perl libraries.
Use the enviormental variable in the perl include section.
Use IIS Diag Trace,Debugger,Process Monitor to track problems.
The rest of fix is working on coding.
Thanks,
Martin
Community Member Award 2011
Rom9854
7 Posts
Re: Issue using perl cgi calling a .exe file
Mar 10, 2011 01:46 PM|LINK
Hello,
Anyway the bug is quite tricky, I made it run on apache and also to the command line but still no improvement under IIS...
Always the same kind of warning which I think prevent the ".exe" to end :Can't call method "close" on an undefined value at C:/Perl/lib/IPC/Open3.pm line 370. And of course no such warning under apache or command line :´(
Is there no way the issue is coming from IIS?
Thanks,
Romain