executing CGI scripts from command line
Hi everyone, I'm having a hard time trying to figure out how to implement this.
Develop a program written in C that will handle encoding and decoding of
* Your program should run from a command-line interface in Linux (preferably)
or DOS. It should prompt the user to enter these items:
3. Phone number
* Once you collect this data, CGI encode it and display the encoded string.
* Decode the CGI data, and display a label and associated value (these should
match exactly what the user entered.)
* Do not link in or use any code except what can be found in the standard
Now from I can set up and make a program that will fulfill the data requirements with executable that a user runs, though I'm not sure how to convert it to CGI. I can also make the CGI script so that if the user goes to a webpage, puts in the information the requirements will be fulfilled. My problem is how do I encode and decode data as CGI from a command line or shell, and can data from an executable be made into CGI data. Thanks.
I am not really sure what it is about, but I will assume that CGI encoding is HTTP GET request encoding (which is URI encoding) which is used primarily by CGI scripts. It is surely not about writing a CGI script. Anyway I am sure that you do not need to run a CGI script with webserver.
http://www.ietf.org/rfc/rfc2396.txt describes URI syntax. I think you need to create a string like name=...&address=...&phone=... which is encoded as to be safe and allowed for URL query part. The interesting part for you in this case is what symbols are allowed and what must be %-escaped (and how it should be done).
Thank you very much, I'm going to focus on just making an executable that asks the user for input and encodes it via URI encoding. The part that was throwing me was how to make a program that is suppose to be run on the back end of a server able to be executed from a command line, though I suspect that finding out and researching URI encoding is the purpose of the assignment (kind of sneaky), because I can make a C program that asks for input and then echoes it back to the user with no difficulty.
Really the part you asked about is not that tricky - if you ever need it, remember that Apache HTTPD just runs CGI scripts like they would be run from command line, but sets additional environment variables (like QUERY_STRING) and can feed POST data to stdin. apache.org has nice manuals for it.. But surely a user will be puzzled to see Content-Type: right before questions.
Thank you for the help Raskin, I installed apache on my machine here at home, and made it a localhost so that I could just test CGI scripts after I made them with my C compiler, (I've written quite a fewn scripts so far in C and PERL with no problems getting them to execute when I type the URL for my localhost). Do you think you could point me to what direction I should be headed next? Personally, I'm thinking of using g++ and writing a C program the user will execute from linux command line it will:
1. ask the user for the input
2. convert it URI style as you suggested
3. then decode the text
4. display it back to the user with labels
Looking at the requirements does this seem sensible or should I be looking at a different approach? Thanks a bunch for your help.
it seems as if you are being asked to implement a rudimentary
CGI enabled server,
this is quite interesting:
homework isn't strictly allowed but in your case you are
not one of those who want their work done for them!
well, I became a bit interested here, and started investigating a bit.
i don't know if you'll find these interesting but I made a simple form
and a shell cgi script to have a look at what goes on.
it illustrates what the script gets from the server..
We did this in uni last year, it's quite easy when you know the little details.
Everything you want to appear on the web page you just printf.
You have to print the following line first though.
To do forms I think the best way is to use POST not GET. To set up the form just do what the above post says. Then the uri information is given on stdin. You can do something like this to read it all.
Just one thing I should point out.
However since this is a command prompt thing, not actually running on a web server, to CGI encode it you would just print it out as name=value?name2=value2 etc. sprintf is useful, just remember to check buffer lengths.
A tip: the "hidden" input element in html is very useful for saving some "state" in your program (HTML is completely stateless).
It seems like they're asking you to do something a little strange since CGI encoding is done by your internet browser, you can probably ignore half of what I said since it relates to actually making a CGI script to run on a web site.
|All times are GMT -5. The time now is 11:14 AM.|