home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / wf_expl / doscl2.c < prev    next >
Text File  |  1992-05-03  |  2KB  |  78 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*                                                                          */
  5. /* COPYRIGHT IBM CORP., 1992                                                */
  6. /*                                                                          */
  7. /* ------------------------------------------------------------------------ */
  8. /*                                                                          */
  9. /*                                                                          */
  10. /* See the DOSCL1.C prolog for a description of the DOSRUN package.         */
  11. /*                                                                          */
  12. /****************************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <process.h>
  16. #include <stdlib.h>
  17. #include <errno.h>
  18. #include <io.h>
  19. #include <dos.h>
  20. #include <fcntl.h>
  21. #include <share.h>
  22. #include <string.h>
  23.  
  24. #define EOFFLAG 26
  25.  
  26. void main( int argc, char *argv[] )
  27. {
  28.    char *buffer;
  29.    int i;
  30.    int handle;
  31.    unsigned int rc;
  32.    int buflen;
  33.    char *temp;
  34.    unsigned int actual;
  35.  
  36.    /* Open tempfile, deny none, read/write access */
  37.    _dos_open( argv[1], O_RDWR | SH_DENYNO, &handle );
  38.  
  39.    /* Find the length of invocation string */
  40.    buflen = 0;
  41.    for (i=2; i<argc; i++) {
  42.       buflen += strlen ( argv[i] ) + 1;
  43.    }
  44.    buflen++;
  45.  
  46.    /* Allocate at least 3 bytes for EOF flag and rc */
  47.    if ( buflen < 3 )
  48.       buflen = 3;
  49.  
  50.    buffer = (char *)malloc( buflen );
  51.  
  52.    /* Build invocation string */
  53.    *buffer = '\0';
  54.    for (i=2; i<argc; i++) {
  55.       strcat ( buffer, argv[i] );
  56.       strcat ( buffer, " " );
  57.    } /* endfor */
  58.  
  59.    /* Redirect stdout and stderr to tempfile */
  60.    dup2( handle, fileno(stdout) );
  61.    dup2( handle, fileno(stderr) );
  62.  
  63.    /* Invoke the executable */
  64.    rc = system( buffer );
  65.  
  66.    /* Write EOF flag followed by rc as the last 3 bytes in tempfile */
  67.    *buffer = EOFFLAG;
  68.    temp = (char *)&rc;
  69.    *(buffer+1) = *temp;
  70.    *(buffer+2) = *(temp+1);
  71.    _dos_write( handle, buffer, 3, &actual );
  72.  
  73.    free( buffer );
  74.    return;
  75.  
  76. }
  77.  
  78.