Cannot read from STDIN

W

William

Perl script in question: http://mkmxg00/cgi/confirmUpload.pl is as
follows:

#!/usr/bin/perl -w

#===============================================================================
# confirmUpload.pl
# once the user clicks "Confirm Modifications", this script picks up the
form's
# newest data from STDIN (POST method), then saves it to the dummylist
#===============================================================================

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $query = new CGI;

# add code that reads in the "Confirm Modifications" request from the CGI
buffer
my $buffer;
read ( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );

# buffer now contains data to be written to the dummylist
open ( OUTFD, "/mkapp/webapps/mxrt/data/extra_desk_tickers.txt" ) or
error("Couldn't open file: $DATAFILE\n");
print ( OUTFD $buffer );
close ( OUTFD );

exit 0;


The javascript code that invoked the above Perl script:
I am currently using XMLHttpRequest as follows:
function saveText( scroll_list, t_area, listToBeUpdated ) {
var updated = new Option();
updated.value = t_area.value;
updated.text = t_area.text;
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected ) {
scroll_list.options[scroll_list.selectedIndex].text = updated.value;
scroll_list.options[scroll_list.selectedIndex].value= updated.value;
break;
}
}
var confirmReq;
var url = "http://mkmxg00/cgi/confirmUpload.pl";
confirmReq = new ActiveXObject( "Microsoft.XMLHTTP" );
confirmReq.onreadystatechange = processReqChange;
confirmReq.open( "POST", url, true );
confirmReq.send( "" );

alert( url );
}

function processReqChange() {
if ( confirmReq.readyState == 4 ) {
if ( confirmReq.status == 200 ) {
alert( "passed!" );
}
}
else {
alert( confirmReq.readyState + ", " + confirmReq.status );
}
}



My problem: nothing is written to
/mkapp/webapps/mxrt/data/extra_desk_tickers.txt

I have already invoked confirmUpload.pl with the XMLHttpRequest confirmReq
(I am using IE 6.0 on Windows XP). Why does the file contains no output
from the CGI buffer?
 
G

Gunnar Hjalmarsson

William said:
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $query = new CGI;

That means that CGI.pm reads STDIN, which is empty afterwords.
# add code that reads in the "Confirm Modifications" request from the
CGI buffer
my $buffer;
read ( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );

Consequently that won't read anything.

Since you are using CGI, why don't you use it to get and parse POSTed data?
 
W

William

That means that CGI.pm reads STDIN, which is empty afterwords.

I don't quite understand what you meant.
so you meant $query contains all the content of my CGI buffer?
Consequently that won't read anything.

Since you are using CGI, why don't you use it to get and parse POSTed data?

as in query->param("parameter_name")?
 
G

Gunnar Hjalmarsson

William said:
I don't quite understand what you meant.
so you meant $query contains all the content of my CGI buffer?

No, $query is just an object reference to the CGI object.
as in query->param("parameter_name")?

Almost. As in $query->param("parameter_name").
--------------^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top