home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum16.lzh / SOFTWARE / C / DIV_UTILITIES / run.c < prev   
C/C++ Source or Header  |  1991-03-24  |  2KB  |  73 lines

  1. /*********************************************************************
  2. file run.c: program description
  3.   fork a process with stdio connected to the terminal
  4. ----------------------------------------------------------------------
  5. shorthand, name and address of authors:
  6.   MM       M. Moser, Jakob-Brucker-Str. 15, 8950 Kaufbeuren
  7. ----------------------------------------------------------------------
  8. version, author, date and report:
  9.   1.0    MM      04.02.91 initial version
  10. ----------------------------------------------------------------------
  11. pecularities:
  12.   none
  13. *********************************************************************/
  14.  
  15.  
  16. /********** include files **********/
  17. #include <stdio.h>
  18. #include <strings.h>
  19. #include "../defs/misc.h"
  20.  
  21.  
  22. /********** external symbols **********/
  23. extern char *getenv();
  24. extern int findArg();
  25.  
  26.  
  27. /********** internal definitions **********/
  28. #define PortName "PORT"
  29.  
  30.  
  31. /********** internal functions **********/
  32.  
  33. /* > help: kurze Funktionsbeschreibung und Fehlertext ausgeben */
  34. void help()
  35. {
  36.     /* Funktionsbeschreibung ausgeben */    
  37.     printf("Syntax: run '<prgname> {<arg>}'\n");
  38.     printf("Function: execute the program <prgname> with stdio ");
  39.     printf("rebound to the terminal\n");
  40.     printf("          (be sure the argument is quoted)\n");
  41.     printf("Options:\n");
  42.     printf("     (none)\n");
  43. }
  44.  
  45.  
  46. /********** main function **********/
  47. main(argc, argv)
  48. int  argc;
  49. char *argv[];
  50. {
  51.     char *p,                                        /* name of port */
  52.          b[MaxStrLen];               /* buffer for new command line */
  53.         
  54.     /* test for invalid arguments or help option */
  55.     if (argc != 2 || findArg("-?", 1, argc, argv) > 0) {
  56.         help();
  57.         exit(0);
  58.     }
  59.  
  60.     /* get name of input, output and error stream */
  61.     if ((p = getenv(PortName)) == NULL)
  62.         ErrorExit("Weird - environment variable PORT not defined!\n");
  63.     
  64.     /* execute the program */    
  65.     sprintf(b, "%s <%s >%s >>%s", argv[1], p, p, p);
  66.     system(b);
  67.     
  68.     exit(0);
  69. }
  70.     
  71.  
  72. /*************************** end of file ****************************/
  73.