home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / launch2.zip / LAUNCH.C
C/C++ Source or Header  |  1993-10-16  |  3KB  |  104 lines

  1. #define INCL_DOS
  2. #define INCL_DOSERRORS
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. typedef struct _SessionResult {
  9.    ULONG ulSessionID;
  10.    ULONG ulResultCode;
  11. } SESSIONRESULT, *PSESSIONRESULT;
  12.  
  13. main (int argc, char *argv[])
  14. {
  15.    int i;
  16.    ULONG retcode, idSession, pid, launched, background;
  17.    STARTDATA sd;
  18.    CHAR szObjBuffer[ CCHMAXPATH ];
  19.    CHAR szPgm[ 1024 ];
  20.    HQUEUE hq;
  21.    REQUESTDATA Request;
  22.    ULONG cbData;
  23.    PVOID pbuf;
  24.    BYTE priority;
  25.    static CHAR szQueueName[] = "\\QUEUES\\PGM1X2X3.MAG";
  26.    PSESSIONRESULT pSessionResult;
  27.  
  28.    retcode = DosCreateQueue( &hq, QUE_FIFO | QUE_CONVERT_ADDRESS, szQueueName );
  29.  
  30.  
  31.    launched = 0;
  32.    if ( retcode ) {
  33.       printf( "DosCreateQueue failed: %d\n", retcode );
  34.    } else for ( i = 1; i < argc; i++ ) {
  35.  
  36.       strcpy( szPgm, argv[i] );
  37.  
  38.       sd.Length = sizeof( sd );
  39.       sd.Related = /* SSF_RELATED_INDEPENDENT  */ SSF_RELATED_CHILD ;
  40.       sd.FgBg = SSF_FGBG_FORE;
  41.       sd.TraceOpt = SSF_TRACEOPT_NONE;
  42.       sd.PgmTitle = NULL;
  43.       sd.PgmName = szPgm;
  44.       sd.PgmInputs = NULL;
  45.       sd.TermQ = szQueueName;
  46.       sd.Environment = NULL;
  47.       sd.InheritOpt = SSF_INHERTOPT_PARENT;
  48.       sd.SessionType = SSF_TYPE_DEFAULT;
  49.       sd.IconFile = NULL;
  50.       sd.PgmHandle = 0;
  51.       sd.PgmControl = SSF_CONTROL_VISIBLE;
  52.       sd.InitXPos = 0;
  53.       sd.InitYPos = 0;
  54.       sd.InitXSize = 0;
  55.       sd.InitYSize = 0;
  56.       sd.Reserved = 0;
  57.       sd.ObjectBuffer = szObjBuffer;
  58.       sd.ObjectBuffLen = sizeof( szObjBuffer );
  59.  
  60.       background = 0;
  61.       retcode = DosStartSession( &sd, &idSession, &pid );
  62.       if ( retcode == ERROR_SMG_START_IN_BACKGROUND ) {
  63.          background = 1;
  64.          retcode = 0;
  65.       }
  66.       if ( retcode ) {
  67.          printf( "launch of %s failed: %d %s\n", szPgm, retcode, szObjBuffer );
  68.       } else {
  69.          printf( "%s launched%s, session:%d pid:%d\n", szPgm,
  70.                   background ? "(background)" : "", idSession, pid );
  71.          launched++;
  72.  
  73.       }
  74.    }
  75.  
  76.    while (launched--) {
  77.       retcode = DosReadQueue( hq, &Request,
  78.                                  &cbData,
  79.                                  &pbuf,
  80.                                  0,
  81.                                  DCWW_WAIT,
  82.                                  &priority,
  83.                                  NULLHANDLE );
  84.       if ( retcode ) {
  85.          printf( "DosReadQueue faild %d\n", retcode );
  86.       } else {
  87.          pSessionResult = (PSESSIONRESULT)pbuf;
  88.          printf( "pid:%d ulData:%d cbData:%d priority:%d ulSession:%d ulResult:%d\n",
  89.             Request.pid,
  90.             Request.ulData,
  91.             cbData,
  92.             (ULONG)priority,
  93.             pSessionResult->ulSessionID,
  94.             pSessionResult->ulResultCode );
  95.          retcode = DosFreeMem( pbuf );
  96.          if ( retcode ) {
  97.             printf( "Dosfreemem failed %d\n", retcode );
  98.          }
  99.       }
  100.    }
  101.  
  102.    return( 0 );
  103. }
  104.