Link to home
Start Free TrialLog in
Avatar of gilbej
gilbej

asked on

CGI on Windows NT

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,
Avatar of edl
edl

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?
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.
Avatar of gilbej

ASKER

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.
I tried this and it seems to be OK, I guess your JAVA program is wrong somewhere, can you show the source code?
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.
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  
Avatar of gilbej

ASKER

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.


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>
ASKER CERTIFIED SOLUTION
Avatar of viro
viro

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gilbej

ASKER

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,
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?
Avatar of gilbej

ASKER

In order to run a java program from the command line you type:

c:\> java JavaAppName

where JavaAppName is the file JavaAppName.class


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.
Avatar of gilbej

ASKER

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?
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.
Avatar of gilbej

ASKER

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.



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 ?

Avatar of gilbej

ASKER

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?
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.
Avatar of gilbej

ASKER

How do I use the windows console program?  By the way, what is the windows console?
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.
Avatar of gilbej

ASKER

I don't have MS VC++, so is there an alternative solution to "consoles"?
What language can you use then?  Maybe BASIC can also do the job by assigning a random file name.