Cannot read from STDIN

Discussion in 'Perl Misc' started by William, Jan 23, 2006.

  1. William

    William Guest

    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?
    William, Jan 23, 2006
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jan 23, 2006
    #2
    1. Advertising

  3. William

    William Guest

    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")?
    William, Jan 23, 2006
    #3
  4. 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
    Gunnar Hjalmarsson, Jan 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    24,959
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    786
    Dan Pop
    Jun 21, 2004
  3. Ben
    Replies:
    2
    Views:
    1,343
    jacob navia
    Aug 29, 2009
  4. Terry Cooper
    Replies:
    7
    Views:
    424
    Janos Sebok
    Jun 9, 2009
  5. Stefano Sabatini
    Replies:
    6
    Views:
    292
    Stefano Sabatini
    Jul 29, 2007
Loading...

Share This Page