473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Perl and C in CGI program

saranjegan
Hello, Though i can make my script work well with perl , when am supposed write a script in C its giving error named 500 internal server error i have even tried with some example programs from net am getting the same error from error log i found its Premature End Of script headers ,while am trying it run on mozila browser it just asking for the download of the exe file, am posting the code below
HTML code :

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <Head>
  3. <title>Test Programs </title>
  4. <FORM ACTION="http://192.168.10.160/cgi-bin/mult.exe">
  5. <P>Please specify the multiplicands:
  6. <INPUT NAME="m" SIZE="5">
  7. <INPUT NAME="n" SIZE="5"><BR>
  8. <INPUT TYPE="SUBMIT" VALUE="Multiply!">
  9. </FORM>
  10.  
C-code :

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5.     char *data;
  6.     long m,n;
  7.     printf("Content-Type:text/html \n \n");
  8.     printf("<HTML>\n");
  9.     printf("<Head>\n");
  10.     printf("<TITLE>Multiplication results</TITLE>\n");
  11.     printf("</Head>\n");
  12.     printf("<H3>Multiplication results</H3>\n");
  13.     data = getenv("QUERY_STRING");
  14.     if(data == NULL)
  15.         printf("<P>Error! Error in passing data from form to script.");
  16.     else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
  17.         printf("<P>Error! Invalid data. Data must be numeric.");
  18.     else
  19.         printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
  20.     printf("</Html>");
  21.     return 0;
  22. }
  23.  
can any suggest what might be the reason , i think this problem is not language (C )related, OS-windows server-Apache,But perl based scripts working fine in the same server
Aug 14 '07 #1
6 2113
KevinADC
4,059 Expert 2GB
ask C coding question in the C forum.
Aug 14 '07 #2
miller
1,089 Expert 1GB
Moving from Perl Forum to C/C++ Forum.

- MODERATOR
Aug 14 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
You might look at this code:

sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
data is declared as a char*. However, it doesn't point to anything.
Aug 14 '07 #4
RRick
463 Expert 256MB
The data variable is set later in the program by getenv and should be valid with non NULL values.

You should be able to run this program as a standalone program, separate from Apache. Before you run it, set the system variable with your values (which might be a little tricky with embedded \n's).

Now you can use gdb or some debugger to find the problem. That way you'll really know where the problem is.
Aug 14 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
The data variable is set later in the program by getenv and should be valid with non NULL values.
Thanks. I didn't see that.
Aug 15 '07 #6
Thanks. I didn't see that.
Hello,
As per your points i tried with very simple program to print a hello statement but it gives the same error , i think the problem is not with the code since it's copied from a Net source , the problem might be with apache configuration for running C based CGI scripts,Do any one have an idea with this can afford your suggestion or suggest me an right place to ask
Aug 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lonelyplanet999 | last post by:
Hi, I'm a newbie to perl and is now studying about perl programming, I read some perl programming tutorials online (enter 'Perl tutorial' at google.com) and also find some sample perl scripts...
3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
3
by: sir.linying | last post by:
My php script is to call perl scipt which makes use of Spreadsheet::ParseExcel module to parse Excel file. I am able to launch php script from command line so that perl script can run and properly...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: megaman1 | last post by:
I’m trying to connect with perl DBD::Oracle on Windows to Oracle DB (Linux). I compiled the Oracle.dll using the commands “perl Makefile.pl” “nmake” and “nmake install”, but when I try to connect...
2
by: IvanIV | last post by:
Hi All, I have trouble with embedding a Perl interpreter into a C program. I would like to replace some subroutine in a Perl script without changing this script from my C program. I need...
24
by: Peter Michaux | last post by:
I have a Perl script that I want to run as a set-user-ID program. Many OSes don't allow scripts run as set-user-ID. To make this script portable, it seems I need to write a C wrapper program that...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.