/************************************************************************/ /* */ /* COPYRIGHT (C) G. KLYNE, 2004 */ /* */ /************************************************************************/ /* * * Module name : SpawnEchoShiftLetters * File name : SpawnEchoShiftLetters.c * * * AMENDMENT RECORD * ================ * * 1. V00.1A 29-Apr-1996 Graham Klyne * Module initially created. * * * MODULE FUNCTION * =============== * Read characters from standard input, and echo them to standard * output replacing each letter with its uppercase equivalent. * * When the end of inptu is reached, report the number of * characters processed to standard error. * */ /************************************************************************/ /* External declarations used */ /************************************************************************/ // #include // #include // #include // #include #include // for errno #include extern int spawnProc ( char* cmd , int* pFdInWrite , int* pFdOutRead , int* pFdErrRead ) ; int main( int argc, char * argv[], char * envp[] ) { /*-- Local variable declarations -----------------------------*/ int sin ; int sout ; int serr ; int e ; char buf[100] ; /*-- Spawn process now -----------------------------------------*/ e = spawnProc( "EchoShiftLetters.exe", &sin, &sout, &serr ) ; printf( "Spawned EchoShiftLetters.exe: sin %i, sout %i, serr %i\n", sin, sout, serr ) ; e = _write( sin, (void *)"abcdefghijklmnopqrstuvwxyz", 26) ; if ( e < 0 ) { printf( "Error writing to sin: %i\n", errno ) ; return 1 ; } printf( "Characters written: %i\n", e ) ; e = _close( sin ) ; if ( e < 0 ) { printf( "Error closing sin: %i\n", errno ) ; return 1 ; } e = _read( sout, (void *)buf, 100) ; if ( e < 0 ) { printf( "Error reading from sout: %i\n", errno ) ; return 1 ; } printf( "Characters read from sout: %i\n", e ) ; buf[e] = '\0' ; printf( "Data: '%s'\n", buf ) ; e = _close( sout ) ; if ( e < 0 ) { printf( "Error closing sout: %i\n", errno ) ; return 1 ; } e = _read( serr, (void *)buf, 100) ; if ( e < 0 ) { printf( "Error reading from serr: %i\n", errno ) ; return 1 ; } printf( "Characters read from serr: %i\n", e ) ; buf[e] = '\0' ; printf( "Data: '%s'\n", buf ) ; e = _close( serr ) ; if ( e < 0 ) { printf( "Error closing serr: %i\n", errno ) ; return 1 ; } /*-- Report number of characters processed ---------------------*/ printf( "SpawnEchoShiftLetters: finished.\n" ) ; return 0 ; } /* End of procedure main */ /************************************************************************/ /* End of module SpawnEchoShiftLetters */ /************************************************************************/