D CGI Hang with fgets
Morgan McDermott
morganmcdermott at gmail.com
Mon Nov 27 09:23:46 PST 2006
Carlos Santander wrote:
> Morgan McDermott escribió:
>> Hi there!
>> I'm trying to make a D CGI script, and one of the essential things it
>> should do is to get POST data. My attempt below in D hangs at
>> fgets()... I've made it output to a file so that it may be tested on a
>> webserver (where I've been testing it). When the script has POST data
>> to get, it performs exactly the same as it does in the console (hangs
>> at fgets()).
>>
>> I've been using a guide to C and CGI as my reference here:
>> http://www.cs.tut.fi/~jkorpela/forms/cgic.html
>>
>> <code>
>> //Imports
>> import std.stdio; //writefln()
>> import std.string; //toString()
>> import std.date : getUTCtime; // time + benchmarking
>> import std.conv; //toInt()
>> import std.stream; //testing only
>> alias char[] string; //ease of use
>>
>> void writeNewLine(string line, string filename) {
>> std.file.append(filename, line~"\n");
>> }
>>
>> extern (C)
>> {
>> char* getPOSTData(uint len = 2048){
>> char *prawData;
>>
>
> Have you tried initializing prawData?
> prawData = new char [len]; // or similar
>
>> printf("hang?");
>> writeNewLine("Hanging point entered \n", "baz.txt");
>>
>> prawData = fgets(prawData, len+1, stdin);
>>
>> writeNewLine("Hanging point exited \n", "baz.txt");
>> printf("Not hanging.. =-)");
>>
>> return prawData;
>> }
>> }
>> extern (C) char* getenv(char*);
>>
>> void main() {
>> string introduction = "New test at " ~ toString(getUTCtime());
>> writeNewLine(introduction, "baz.txt");
>> char *pdataLength= getenv("CONTENT_LENGTH");
>> string scontentLength = toString(pdataLength);
>> //Ensure no conversion error when no post data is passed
>> if(scontentLength == ""){
>> scontentLength = "0";
>> }
>> uint contentLength = toInt(scontentLength);
>> char *ppostData = getPOSTData();
>> writefln("Post Data: %s", toString(ppostData));
>> writeNewLine("Post Data: " ~ toString(ppostData), "baz.txt");
>> }
>> </code>
>>
>> Any ideas?
>>
>> Thank you very much for your time,
>> ~Morgan McDermott
>
>
Carlos,
Good idea, and thanks for the reply. Unfortunately, the script still
hangs at the same point. I've done a bit more work and an essentially
equivilant C script also hangs at this point, so I doubt that this is a
D-problem. All the same, any help from this great community is very much
appreciated :).
Thanks again,
~Morgan McDermott
More information about the Digitalmars-d-learn
mailing list