home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / CALLBOX.ZIP / BOXMON.C next >
Text File  |  1989-10-22  |  2KB  |  65 lines

  1.  
  2. /* A simple DOS box client */
  3. /* P. Fitzsimmons Sun  10-22-1989  06:37:41 */
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <string.h>
  8. #include <process.h>
  9. #include <fcntl.h>
  10. #include <share.h>
  11. #include <conio.h>
  12. #include <errno.h>
  13. #include "dostalk.h"
  14.  
  15.  
  16. #define TRUE 1
  17. #define FALSE 0
  18.  
  19. extern int far pascal DosSleep(long val);
  20. #pragma comment(lib, "api.lib")         /* this is the lib BIND uses. DosSleep() is in there */
  21.  
  22. void main(void)
  23. {
  24.     int hpipe;
  25.     static char buf[256];
  26.     unsigned bytes, wbytes;
  27.     int done = FALSE;
  28.  
  29.     printf("BOXMON is waiting for an OS/2 session to send a command using CALLBOX.\n");
  30.     printf("Press ESC to quit.\n");
  31.  
  32.     while(!done){
  33.         errno = 0;
  34.         DosSleep(100L);
  35.         if(!_dos_open(pipe, O_RDWR | SH_DENYNO, &hpipe)){
  36.             _dos_write(hpipe, ackmsg1, sizeof(ackmsg1), &wbytes);
  37.             if(!_dos_read(hpipe, buf, sizeof(buf), &bytes)){
  38.                 printf("Read %d, %s\n", bytes, buf);
  39.                 if( bytes < sizeof(buf) ){
  40.                     buf[ bytes ] = 0;  // make asciiz
  41.                     printf("Executing: '%s'\n", buf);
  42.                     system(buf);
  43.                     /* with some extra work, you could call spawn() instead
  44.                     * and return the errorlevel back to the os/2 session.
  45.                     */
  46.                     _dos_write(hpipe, ackmsg2, sizeof(ackmsg2), &wbytes);
  47.                 }
  48.             }
  49.             _dos_close(hpipe);
  50.         }
  51.         else{
  52.             if( errno != ENOENT && errno != EACCES ){
  53.                 printf("Could not open %s, %s.", pipe, _strerror(NULL));
  54.                 done = TRUE;
  55.             }
  56.             else
  57.                 printf("Waiting...\r");
  58.         }
  59.         if( kbhit() )
  60.             done = TRUE;
  61.     }
  62. }
  63.  
  64. 
  65.