server-side JavaScript: Example 4: Pipe class

Discussion in 'Javascript' started by GVDC, Jun 28, 2008.

  1. GVDC

    GVDC Guest

    Example server-side JavaScript Web script, Pipe class


    //sending email using Pipe class and sendmail:
    //
    printf("<html><body>");

    var pipeobj = new Pipe("/usr/sbin/sendmail ");

    //set errno 0
    Server.errno(0);

    if ( pipeobj.open()==true ) {
    var smsg = ""
    +"From: \n"
    +"To: \n"
    +"Subject: Webscript test email\n"
    +"\n"
    +"Text text text\n"
    +"more text some more text etc.\n"
    +"\n"
    ;

    //writing ok
    if ( pipeobj.write(smsg)!=(-1) ) {
    pipeobj.close(1); //close write end
    printf("<pre>");
    printf(pipeobj.read()); //read and print output, if any
    printf("</pre>");
    }
    //error
    else {
    printf("Failed writing to pipe: " , Server.errnstr() ,"<br\n>");
    printf("Msg text:<br>" , smsg ,"<br\n>");
    }

    var xstatus = pipeobj.close(); //final close completely closes pipe and returns pipe status

    //if non-zero there was an error or process unclean exit
    if ( xstatus!=0 ) {
    printf("Closing pipe indicate failure [exit status " , xstatus ,"]<br\n>");
    printf("System status: " , Server.errnstr() ,"<br\n>");
    }

    }
    else {
    printf("Opening pipe failed, system status: " , Server.errnstr() ,"<br\n>");
    }


    printf("</body></html>");





    --
    GVDC, Jun 28, 2008
    #1
    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. lee, wonsun
    Replies:
    1
    Views:
    480
    Jack Klein
    Nov 2, 2004
  2. Replies:
    1
    Views:
    217
    Ben Morrow
    Jun 2, 2004
  3. GVDC
    Replies:
    0
    Views:
    370
  4. GVDC
    Replies:
    1
    Views:
    142
    Thomas 'PointedEars' Lahn
    Jun 28, 2008
  5. GVDC
    Replies:
    0
    Views:
    132
Loading...

Share This Page