View previous topic :: View next topic |
Author |
Message |
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
Posted: Sun Feb 23, 2003 6:36 pm Post subject: cgi and binary executables |
|
|
i searched the net, i searched alot
but i couldn't find anything that expains how to run a let's say c++ binary that writes output via cout .
in windows i just compiled the c++ source and placed the exe in the apache cgi-bin dir, and accessed it with http://localhost/cgi-bin/myapp.exe
and the output of the file (of course i sent headers) was shown in the browser.
if i do it in linux or freebsd it won't work.
the file is in the cgi-bin dir but not found
The requested URL /cgi-bin/cos was not found on this server.
the apache error_log:
[Sun Feb 23 19:36:07 2003] [error] [client 127.0.0.1] script not found or unable to stat: /usr/local/apache/cgi-bin/cos
how to make it work |
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 6:40 pm Post subject: |
|
|
What says Code: | ls -l /usr/local/apache/cgi-bin/cos | ? |
|
Back to top |
|
|
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
Posted: Sun Feb 23, 2003 6:59 pm Post subject: |
|
|
bash-2.05b# ls -l
total 8
-rwxrwxrwx 1 root root 5377 Feb 23 00:01 cos |
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 7:07 pm Post subject: |
|
|
Try to increase Apache's verbose level (LogLevel debug) and see if this gives more information. |
|
Back to top |
|
|
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
Posted: Sun Feb 23, 2003 7:24 pm Post subject: |
|
|
slap me
cgi-bin dir is set to
/usr/local/apache/cgi-bin/
i copied the file there and it worked
but it doesn't seem to accept arguments
Code: |
using namespace std;
#include <iostream.h>
int main(int argc, char* argv[])
{
cout << "\"Content-type: text/html\"\n\n";
cout << "<HTML>" << endl;
cout << "<BODY>" << endl;
cout << "Hallo von mir<BR>" << endl;
if (argc >0)
{
for (int i = 1 ; i <= argc ; i++)
{
if (argv[i] != NULL)
cout << "arg " << i << " " << argv[i] << "<BR>" << endl;
}
}
cout << "</BODY>" << endl;
cout << "</HTML>" << endl;
return 0;
}
|
also, the output looks like this
Code: |
<HTML>
<BODY>
Hallo von mir<BR>
</BODY>
</HTML>
|
|
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 7:43 pm Post subject: |
|
|
Try this: Code: | using namespace std;
#include <iostream.h>
int main(int argc, char* argv[])
{
cout << "Content-type: text/html\n\n";
cout << "<HTML>" << endl;
cout << "<BODY>" << endl;
cout << "Hallo von mir<BR>" << endl;
for (int i = 1 ; i < argc ; i++)
{
cout << "arg " << i << " " << argv[i] << "<BR>" << endl;
}
cout << "</BODY>" << endl;
cout << "</HTML>" << endl;
return 0;
}
|
Outputs Code: | Content-type: text/html
<HTML>
<BODY>
Hallo von mir<BR>
arg 1 a<BR>
arg 2 b<BR>
</BODY>
</HTML>
|
But I don't think this is the problem why apache can't find your program... |
|
Back to top |
|
|
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
Posted: Sun Feb 23, 2003 8:45 pm Post subject: |
|
|
no, you got me wrong
apache is able to find it now, i put it in the wrong dir
but
the output in the browser doesn't show the output in html format, but in plain text |
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 8:49 pm Post subject: |
|
|
dalu wrote: | the output in the browser doesn't show the output in html format, but in plain text |
Even when you corrected the line which prints out the content type to not contain the extra " (quotes)? See the code I replied: Code: | cout << "Content-type: text/html\n\n"; |
|
|
Back to top |
|
|
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 9:25 pm Post subject: |
|
|
Arguments are not passed as command line arguments to CGIs, but via an environment variable QUERY_STRING (="a=1&b=2&c=3") which has to be parsed by your program. |
|
Back to top |
|
|
dalu Guru
Joined: 20 Jan 2003 Posts: 530
|
Posted: Sun Feb 23, 2003 10:19 pm Post subject: |
|
|
hmm isn't this rather unsafe?
lets say, 2 users are sending 2 different requests to the the serverapp
the QUERY_STRING env var is overwritten by the least request
but, ok
argv[1] contains the request i guess, unlike in windows , where every argument is assigned its own argv index
edit: no argv[1] doesn't contain anything when "=" is in the query string
hmm maybe apache needs to be compiled in a special way, or configured
ok vielen dank |
|
Back to top |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Feb 23, 2003 10:31 pm Post subject: |
|
|
For each request, apache spawns a new process of your CGI program and give them separate and individual environments. They don't overwrite each other.
char *const envp[]
will be the process' environment. This isn't necessarily the same for all processes.
If windows does it its own way, it does it not the CGI way. Were you talking about the windows apache?
kein Problem |
|
Back to top |
|
|
|