OpenVMS Source Code Demos

PIPE_DEMO_CHILD.C

//=====================================================================
// title : pipe_demo_child.c
// source: http://h41379.www4.hpe.com/doc/732final/5763/5763pro_026.html
// target: DECC on OpenVMS
//=====================================================================

#include <stdio.h>					//
#include <unistd.h>					//
#include <string.h>					//

main() {
    char msg1[] = "child: writing START to stderr";	//
    char msg2[] = "child: received msg: ";		//
    char msg3[] = "child: writing FINISH to stderr";	//
    char buf1[80];					//
    char buf2[80];					//
    int  nbytes;					//
    //
    // channel numbers:
    //   0 = stdin  (sys$input)
    //   1 = stdout (sys$output)
    //   2 = stderr (sys$error)
    //
    write(2, msg1, sizeof(msg1));			// send something to stderr(2)
    nbytes = read(0, buf1, sizeof(buf1));		// read something from stdint(0)
    if (nbytes>=0) {					//
	strcpy(buf2, msg2);				// copy msg2 into buf2
	strcat(buf2, buf1);				// append buf1 into buf2
	write(1, buf2, strlen(buf2));			// send modifed msg back to stdout(1)
    }
    write(2, msg3, sizeof(msg3));			// send something to stderr(2)
}