home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / launch1.zip / LAUNCH.C next >
C/C++ Source or Header  |  1991-06-08  |  2KB  |  71 lines

  1. #include <os2.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define LENGTH 40
  6. #define FLAG 2
  7. #define ENVS 0L
  8.  
  9. main(argc,argv)
  10.  
  11. int argc;
  12. char *argv[];
  13.  
  14. {
  15. char *ChildName;            /*pointer for called name*/
  16. char *LaunchArgs;                       /*pointer for new args*/
  17. char *CommandLine;                      /*pointer for new command line*/
  18. char FailBuffer[40];                    /*buffer for fail object name*/
  19. char *ptr;                              /*pointer for character transfer*/
  20.  
  21. int  rc;                                /*function return code*/
  22. int i,j;                /*index for character transfer*/
  23.  
  24. struct RetInfo ChildID;            /*child process ID*/
  25.  
  26. /*check to see if a command line argument was passed*/
  27.  
  28. if(argc != 2)
  29.   printf("Application name not passed to 'Launch'...program aborted.\n");
  30.  
  31.  
  32. /*assign name of called application to ChildName*/
  33.  
  34. ChildName = argv[1];
  35.  
  36.  
  37. /*Prompt user and get new command line parameters*/
  38.  
  39. printf("Enter command line arguments for %s:\n",ChildName);
  40. gets(CommandLine);
  41.  
  42.  
  43. /*Build new set of command line arguments*/
  44.                         /*Argv[0]*/                                         
  45. ptr=ChildName;                                  /*set ptr to file name*/
  46. for(i=0;i<(strlen(ChildName));i++)        /*for length of file name*/
  47.   LaunchArgs[i]=*ptr++;                /*copy characters*/
  48. LaunchArgs[i++] = '\0';                /*NULL terminate argv[0]*/
  49.  
  50.                         /*Argv[1...]*/
  51. ptr=CommandLine;                                /*reset ptr to command line*/
  52. for(j=0;j<(strlen(CommandLine));j++)        /*for length of command line*/
  53.   LaunchArgs[i+j]=*ptr++;                       /*copy characters*/
  54. LaunchArgs[i+j] = '\0';             /*NULL terminate command line*/
  55.  
  56.  
  57. /*Call program with new arguments*/
  58.  
  59. if(rc=DosExecPgm(FailBuffer,LENGTH,FLAG,LaunchArgs,ENVS,&ChildID,ChildName))
  60.   {
  61.   printf("DosExecPgm error #:%u\n",rc);
  62.   printf("Fail Object Buffer contains:%s\n",FailBuffer);
  63.   exit(rc);
  64.   }
  65.  
  66.  
  67. /*Quit and leave child running*/
  68.  
  69. exit(0);
  70. }
  71.