CGI: Calling C is different?

H

Huey

Hi All,

I wonder that is there any difference of calling C executable in CGI
from the "normal"? A few days ago, with helps from Tad, Jim,
Christian, I did make my perl scripts got returns from C executables.
Thanks go to Jim, Christian, and Tad! However, when I put my code into
CGI, broken! I can't figure out the kicker, thus here for help. My
code test.pl:

#!/usr/bin/perl
print "Content-type: text/html", "\n\n\n";

my $mytest = "./c_hello.exe";
open TEST, "$mytest |" or die "Error running $mytest: $!\n";
while(<TEST>) {
print "The return from C is: $_", "\n";
}
close (TEST);
exit (0);

This piece of code works in command-line: %perl test.pl, and prints
out "Hi All". But, it does not work as a CGI script with a html file.
Anybody helps me out? Thanks a lot, and wish you have a happy NEW
YEAR!

Huey
 
T

Tad McClellan

Huey said:
I wonder that is there any difference of calling C executable in CGI
from the "normal"?


No.

And there is no such thing as a "C executable".

Once it is compiled to an executable, it is an executable, regardless
of what language it was originally written in.

when I put my code into
CGI, broken!

I wonder what "broken" means when you say it.

What does "broken" mean when you say it?

A white screen?

A black screen?

A screenful of gobbledy gook?

Messages in your server log?

Too much output?

Too little output?

The wrong output?

Smoke comes out of the computer's vents?

it does not work as a CGI script


I wonder what "does not work" means when you say it.

Anybody helps me out?


It is much easier to make a diagnosis if we have one or more symptoms.

Have you seen the Posting Guidelines that are posted here frequently?



WAG:
use an absolute path instead of a relative path to the exe
 
C

Charles DeRykus

Hi All,

I wonder that is there any difference of calling C executable in CGI
from the "normal"? A few days ago, with helps from Tad, Jim,
Christian, I did make my perl scripts got returns from C executables.
Thanks go to Jim, Christian, and Tad! However, when I put my code into
CGI, broken! I can't figure out the kicker, thus here for help. My
code test.pl:

#!/usr/bin/perl
print "Content-type: text/html", "\n\n\n";

my $mytest = "./c_hello.exe";
open TEST, "$mytest |" or die "Error running $mytest: $!\n";
while(<TEST>) {
print "The return from C is: $_", "\n";
}
close (TEST);
exit (0);

This piece of code works in command-line: %perl test.pl, and prints
out "Hi All". But, it does not work as a CGI script with a html file.
Anybody helps me out? Thanks a lot, and wish you have a happy NEW
YEAR!

I could guess but you'd probably be better off doing a little research
on your own. Start with 'perldoc -q cgi' for some relevant tidbits and
faq's.

One good idea, whether the setting is CGI or not, is to set warnings
and strictures. Additionally, redirecting stderr to the screen can
be very useful during CGI development.

use CGI::Carp (fatalsToBrowser warningsToBrowser);


hth,
 
J

James Willmore

On 25 Dec 2003 21:01:27 -0800
I wonder that is there any difference of calling C executable in CGI
from the "normal"? A few days ago, with helps from Tad, Jim,
Christian, I did make my perl scripts got returns from C
executables. Thanks go to Jim, Christian, and Tad! However, when I
put my code into CGI, broken! I can't figure out the kicker, thus
here for help. My code test.pl:

#!/usr/bin/perl
print "Content-type: text/html", "\n\n\n";

my $mytest = "./c_hello.exe";
open TEST, "$mytest |" or die "Error running $mytest: $!\n";
while(<TEST>) {
print "The return from C is: $_", "\n";
}
close (TEST);
exit (0);

This piece of code works in command-line: %perl test.pl, and prints
out "Hi All". But, it does not work as a CGI script with a html
file. Anybody helps me out? Thanks a lot, and wish you have a happy
NEW YEAR!

perldoc -q 'cgi'

There's a FAQ mentioned in the responses
(http://www.perl.org/CGI_MetaFAQ.html)
that will give information on how to tackle this problem.

My guess (and it's only a guess) is the script is not executable, has
an extention that the web server doesn't like, and may be in a
directory that is not allowed to execute script. However, please read
over the information given above to (dis)prove what I've said.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
So, what's with this guy Gideon, anyway? And why can't he ever
<remember his Bible?
 
G

Gary E. Ansok

Hi All,

I wonder that is there any difference of calling C executable in CGI
from the "normal"? A few days ago, with helps from Tad, Jim,
Christian, I did make my perl scripts got returns from C executables.
Thanks go to Jim, Christian, and Tad! However, when I put my code into
CGI, broken! I can't figure out the kicker, thus here for help. My
code test.pl:

#!/usr/bin/perl
print "Content-type: text/html", "\n\n\n";

my $mytest = "./c_hello.exe";
open TEST, "$mytest |" or die "Error running $mytest: $!\n";

This runs the "c_hello.exe" program located in the current directory
(which is not necessarily the same as the directory where the Perl
script is located). When your script runs as a CGI script, what is
the current directory?

Another possibility is that the CGI script runs under a different
UID (often "nobody") with very limited permissions -- perhaps this
UID does not have permission to access your C executable.

My recommendation is to use a complete path to the program when
defining $mytest. Alternatively, if your script must look for
files in the directory where the script lives, look into the FindBin
module.

Did your CGI script print the "Error running $mytest" message? If it
did, it probably went to your Web server's log files. What message
was printed for the $! variable? Knowing that would help us help you,
and might even help you resolve the problem without our help. If you
can't check your server's error log files, then either don't use die()
or arrange for the messages to be sent somewhere where you can see them
(use CGI::Carp qw(fatalsToBrowser) is one possibility --
perldoc CGI::Carp for more info).

Gary Ansok
 
M

Michael Capone

Hi All,
[snip]

#!/usr/bin/perl
print "Content-type: text/html", "\n\n\n";

my $mytest = "./c_hello.exe";
open TEST, "$mytest |" or die "Error running $mytest: $!\n";
while(<TEST>) {
print "The return from C is: $_", "\n";
}
close (TEST);
exit (0);

My memory is a bit rusty, as it's been a few years. But I had a
problem similar to this with IIS 4.0 not capturing pipe'd data from
within CGI programs. It was an IIS security thing, not a perl issue.
(I'm assuming that you're running IIS since you're trying to capture
output from a .EXE file; forgive me if this is incorrect.) You might
want to repost this question to an IIS forum, where I'm sure someone
will recognize it as a common issue over there.
This piece of code works in command-line: %perl test.pl, and prints
out "Hi All". But, it does not work as a CGI script with a html file.

If someone hasn't already mentioned it, this is usually a good
indicator that it's probably not an issue with Perl, but rather with
your config / server setup / etc. Again, I'd steer you towards an IIS
newsgroup (if appropriate).
Thanks a lot, and wish you have a happy NEW
YEAR!

And also to you!

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top