home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / sysutl / err_ret.arc / ERR_RET.C next >
Encoding:
C/C++ Source or Header  |  1989-09-21  |  1.1 KB  |  48 lines

  1. /* ERR_RET, a program to run another program reporting
  2.     the error return value.
  3.  
  4.     Steven A. Fischkoff, M.D.
  5.     Last modified 9/20/89
  6.     Placed in the public domain; may be freely used and copied.
  7. */
  8.  
  9. #include <process.h>
  10. #include <stdio.h>
  11. #include <errno.h>
  12.  
  13. extern int errno;
  14.  
  15. void main (int argc, char **argv)
  16.  
  17.     {
  18.     int err_return;
  19.     int map [22];
  20.     char *err_msgs [] = {
  21.         "The argument list was too long.\n",
  22.         "There was an invalid argument.\n",
  23.         "The path or file name was not found.\n",
  24.         "There was an internal formatting error.\n",
  25.         "There was not enough memory to run your program.\n"
  26.     };
  27.         map [20] = 0;
  28.         map [19] = 1;
  29.         map [2]  = 2;
  30.         map [21] = 3;
  31.         map [8]  = 4;
  32.  
  33.     if (argc < 2) {
  34.         printf ("\nERR_RET, by Steven Fischkoff, M.D., 9/20/89.\n\n");
  35.         printf ("ERR_RET Program_name [parameters, switches, etc.]\n");
  36.         exit (1);
  37.     };
  38.  
  39.     err_return = spawnvp (P_WAIT, argv [1], &argv [1]);
  40.     if (err_return == -1) {
  41.         printf ("\nUnsuccessful operation: ");
  42.         printf ("%s", err_msgs [map [errno]]);
  43.         exit (2);
  44.     };
  45.  
  46.     printf ("\n\nProgram returned error level = %d\n", err_return & 255);
  47.     exit (0);
  48.     }; /* end of main */