server-side JavaScript: Example 4: Pipe class

G

GVDC

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 (e-mail address removed)");

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

if ( pipeobj.open()==true ) {
var smsg = ""
+"From: (e-mail address removed)\n"
+"To: (e-mail address removed)\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>");





--
 

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

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top