home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / waitne.zip / WAITFOR.CPP < prev    next >
C/C++ Source or Header  |  1995-01-04  |  2KB  |  46 lines

  1. #define INCL_DOSPROCESS   // Process and thread values
  2. /* waitfor.cpp
  3.  * This program is public domain.  Do whatever you want with it.  Use at your
  4.  * own risk.
  5.  *
  6.  * The main purpose for this program is to wait for the user to log into the
  7.  * network before attempting to run anything from the network.  WAITFOR.EXE
  8.  * takes two, and only two arguments: 1: The full path name of a file on the
  9.  * network, and 2: The number of seconds between attempts to find the file.
  10.  * The "wait" routine uses DosSleep(), so this is a VERY low priority program.
  11.  * It shouldn't slow down the rest of your system.  Please let me know of any
  12.  * problems, or fix them yourself.
  13.  *
  14.  * WAITFOR was written and compiled with Borland C++ for OS/2 v1.5.
  15.  * Jeff Lamb, CIS:76256,2123
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <os2.h>
  21.  
  22. void main(int argc, char* arg[])
  23. {
  24.   if(argc != 3)
  25.     printf("\nWAITFOR fullpathname seconds");
  26.   else
  27.   {
  28.     FILE *fileh;
  29.     ULONG   TimeInterval = atoi(arg[2]);  // Interval in milliseconds
  30.     APIRET  rc;                           // Return code for DosSleep
  31.  
  32.     printf("\nWaiting for \"%s\" every %i second(s).\n",arg[1],TimeInterval);
  33.  
  34.     while(! (fileh = fopen(arg[1],"r")))  // Until we see the file
  35.     {
  36.       printf(".");
  37.       rc = DosSleep(TimeInterval*1000);   // Go to sleep
  38.       if (rc != 0)
  39.     printf("DosSleep error: return code = %ld", rc);
  40.  
  41.     }; // while
  42.  
  43.     printf("!");
  44.     fclose(fileh);
  45.   }; // if
  46. }; // main()