Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Cannot read from STDIN

Reply
Thread Tools

Cannot read from STDIN

 
 
William
Guest
Posts: n/a
 
      01-23-2006
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[i].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?

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-23-2006
William wrote:
>
> 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?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
William
Guest
Posts: n/a
 
      01-23-2006
On Mon, 23 Jan 2006, Gunnar Hjalmarsson wrote:

> William wrote:
>>
>> use CGI;
>> use CGI::Carp qw(fatalsToBrowser);
>> use strict;
>>
>> my $query = new CGI;

>
> 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?

>
>> # 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?


as in query->param("parameter_name")?
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-23-2006
William wrote:
> On Mon, 23 Jan 2006, Gunnar Hjalmarsson wrote:
>> William wrote:
>>>
>>> my $query = new CGI;

>>
>> 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?


No, $query is just an object reference to the CGI object.

>>> # 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?

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


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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 1 Week Ago 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57