Solved

CGI on Windows NT

Posted on 1997-08-20
23
377 Views
Last Modified: 2013-12-25
I want to setup my Windows NT Server that is running IIS to enable .exe
files to execute when accessed via cgi.  Currently, when I try to access
a CGI program I get the following message:

CGI Error

The specified CGI application misbehaved by not returning a complete set
of HTTP headers. The headers it did return are:


with no headers returned.  Can anyone offer me some help on this one?


Thanks,
0
Comment
Question by:gilbej
  • 9
  • 7
  • 4
  • +3
23 Comments
 

Expert Comment

by:edl
ID: 1829741
It may be as simple as you are not sending
"Content-type: text/html\r\n\r\n"

Can you post a simple script that is not working?
0
 
LVL 7

Expert Comment

by:faster
ID: 1829742
edl is correct, probably your exe is terminated before it gets the chance to print the header.  Try to run it at command line first and see how.
0
 

Author Comment

by:gilbej
ID: 1829743
The script I am using is a java program.  The program contains the "content-typ: text/html\r\n\r\n".  The way I am trying to execute the java application is using the POST method to http://myweb.server.com/scritps/java.exe?JavaApplication.  Where the java.exe is the java runtime program and the JavaApplication is the JavaApplication.class file in the scripts directory.  The solution has some thing to do with the registry setup, I think so.
0
 
LVL 7

Expert Comment

by:faster
ID: 1829744
I tried this and it seems to be OK, I guess your JAVA program is wrong somewhere, can you show the source code?
0
 
LVL 5

Expert Comment

by:icd
ID: 1829745
To isolate your problem write a program (perl if you have it) which is the minimum 'hello world' type program.

If it does not work it is a server configuration problem.
If it *does* work then it is a problem with your Java program.
0
 

Expert Comment

by:edl
ID: 1829746
Ok, if you are doing this then java.exe has to be in your cgi directory.  You may be better of association the java program with it's extention.  Just as .exe is associated to run as and executable.

Also the ? is not a POST METHOD. (/java.exe?JavaApplicationTHOD.)

What does the program output when you run it from the command line?

Good luck  
0
 

Author Comment

by:gilbej
ID: 1829747
Here is the source code for the Java Application:

import java.io.*;

public class JavaApplication
{
   public static void main (String args[])
   {
      System.out.println("Content-type: text/html\n\n");
      System.out.println("Hello World<BR>");

  }
}

I tested this Java application by adding code to write to a file in order to determine if this application was being executed.  It turns out that the file was not created, therefore, this application was apparently never executed.  That is why I think I  need to make setup changes in the registry.


0
 

Expert Comment

by:edl
ID: 1829748
True, that's why I was wondering what you got from the command line.  If you can't run it from the command line, I don't think you can run it from the server.

Associate the java programs with the actual java interpreter so you can run them from the command line.  Then JavaApplication, should give you something like

Content-type: text/html


Hello World<BR>
0
 
LVL 1

Accepted Solution

by:
viro earned 100 total points
ID: 1829749
gilbej,

you must compile yours CGI in 32 bits compiler, like MS C++ - Console application - 32 bits.


Hope it's help!


Vitor Rodrigues
   Portugal
0
 

Author Comment

by:gilbej
ID: 1829750
What are the "32 bit console" appliations?  You mentioned MS C++, are there any other "consoles" I could use to test this out with?  I don't have MS C++.


Thanks,
0
 

Expert Comment

by:edl
ID: 1829751
I thought you were writing java programs?  What happens when you run the program from the command line?  What is the exact
line you use to run it?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:gilbej
ID: 1829752
In order to run a java program from the command line you type:

c:\> java JavaAppName

where JavaAppName is the file JavaAppName.class


0
 
LVL 7

Expert Comment

by:faster
ID: 1829753
As long as you compile it using javac, it is OK.  There is no other "32bit compliler" for java.

I tried the same program on my pc with microsoft personal web server (win95) and it is OK.  But if this does not work on NT,
it is becoming quite difficult for you.  To setup the registry is easy, you need to add a string value to associate ".class" with "java.exe", however, java.exe does not accept the ".class" extension, I mean, you have to run it as "java myclass" instead of "java myclass.class", but the server will pass the latter and cause an error.  Maybe you first try to associate .class with java.exe in shell.  To do this, just use Explorer and select any .class file and double click on it, then select java.exe.  After this, in the url remove java.exe and only leave the name of your class.
0
 

Author Comment

by:gilbej
ID: 1829754
The cgi problem I am experiencing is on IIS for Windows NT Server.  I can get this to work fine with Personal Web Server on a Win95 machine.  I just need help on WinNT.  The association process of .class and java.exe does not work.  The solution, I am pretty sure, has to do with registry settings for .exe and/or a .dll in the winnt\system32 directory.  My thoughts are that there may be a .dll that can be used to make this .exe work ... I don't  know for sure.  Any other thoughts?
0
 
LVL 7

Expert Comment

by:faster
ID: 1829755
There is a way that should work, but not an elegant one: write a very simple program, which will accept a command line argument, such as "myclass.class", then execute "java.exe myclass".  (all the program do is just remove the .class extension so the java.exe can accept it)  If you don't know how to associate your own program with .class (or other extension you choose) on IIS, I can give you the exact registry setting.
0
 

Author Comment

by:gilbej
ID: 1829756
I tried this using .bat files.  I created a .bat file that contained the following code:

echo Content-type text/html
echo.
echo.
java MyClass
exit


The problem with this option is that the output from the MyClass.class program is never displayed back to STDOUT.  The MyClass.class application executes, but the System.out.println statements are never displayed back to the STDOUT.  It appears that the MyClass.class application is being executed in a "sub shell" of the .bat file, which does not accept the STDOUT from the "sub shell".  If you have a suggestion on how to fix this, that would be a valuable solution to my problem as well.



0
 
LVL 2

Expert Comment

by:aleshka
ID: 1829757
Try to redirect the java's output to some temp file and then type it:

echo Content-type text/html
echo
echo
java MyClass > /temp/MyClass.tmp
type MyClass.tmp
exit

My be this will help ?

0
 

Author Comment

by:gilbej
ID: 1829758
I have implemented this
echo Content-type text/html
                       echo
                       echo
                       java MyClass > /temp/MyClass.tmp
                       type MyClass.tmp
                       exit
before and it works, but there is one small problem ... what happens when two or more people access the script?  They will overwrite each other.  Is there a way to get a Process ID in WinNT using the Dos interface in order to uniquely name the output file?
0
 
LVL 7

Expert Comment

by:faster
ID: 1829759
I am afraid that you can not use batch file for that.  You can consider using windows console program which can use win32 API, then this will not be a problem.
0
 

Author Comment

by:gilbej
ID: 1829760
How do I use the windows console program?  By the way, what is the windows console?
0
 
LVL 7

Expert Comment

by:faster
ID: 1829761
A windows console program is quite like a DOS program, it will open a dos window and no UI is needed.  The difference is that such program can make use of the Win32 APIs.  Normally you write it in C/C++.  If you have microsoft visual C++, it will be as easy as creating a normal DOS program.
0
 

Author Comment

by:gilbej
ID: 1829762
I don't have MS VC++, so is there an alternative solution to "consoles"?
0
 
LVL 7

Expert Comment

by:faster
ID: 1829763
What language can you use then?  Maybe BASIC can also do the job by assigning a random file name.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now