int main( void ) { unsigned char *pCmdline; STARTDATA sd; /* structure defined in bsedos.h */ STATUSDATA statusData; char *buffer; char *p1, *p2; char *doscl2; ULONG action; BOOL Done, Done2=FALSE; /* Set exception handler for CTRL-C and CTRL-BREAK. */ if ( SIG_ERR==signal(SIGILL, handler ) || SIG_ERR==signal(SIGTERM, handler ) || SIG_ERR==signal(SIGBREAK, handler ) ) exit(2); /* Get a pointer to the command line. */ pCmdline = get_cmdline( ); /* Get the executable directory, use it for doscl2.exe */ p1 = pCmdline + strlen( pCmdline ); p2 = p1 + 1; while ( p1 != pCmdline && *(p1-1) != '\\' && *(p1-1) != '/' ) --p1; *p1 = '\0'; /* Fully qualify doscl2.exe */ doscl2 = malloc( strlen(pCmdline) + strlen("doscl2.exe") + 1 ); strcpy( doscl2, pCmdline ); strcat( doscl2, "doscl2.exe" ); /* Open a tempfile for doscl2.exe to write and doscl1.exe to read */ tempfile = tmpnam( NULL ); if ( (rc=DosOpen( tempfile, &handle, &action, 0, FILE_NORMAL, OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, 0 )) != 0 ) { return rc; } /* Construct the input parameter string to doscl2.exe */ buffer = malloc( strlen(tempfile) + strlen(p2) + 2 ); strcpy( buffer, tempfile ); strcat( buffer, " " ); strcat( buffer, p2 ); sd.Length = 32; sd.Related = SSF_RELATED_CHILD; sd.FgBg = SSF_FGBG_BACK; sd.TraceOpt = SSF_TRACEOPT_NONE; sd.PgmTitle = "WF/2 DOS Client"; sd.PgmName = doscl2; sd.PgmInputs = buffer; sd.TermQ = NULL; sd.Environment = NULL; sd.InheritOpt = SSF_INHERTOPT_PARENT; sd.SessionType = SSF_TYPE_WINDOWEDVDM; statusData.Length = 6; statusData.SelectInd = 0; statusData.SelectInd = 0; if (!DosStartSession( &sd, &sess_id, &pid )) Done = FALSE; /* Wait for doscl2.exe to finish, keep reading tempfile at the same time */ while( !Done ) { if ( DosSetSession( sess_id, &statusData ) ) Done = TRUE; DosSleep(5000); Done2 = ReadData( handle ); } while ( !Done2 ) { Done2 = ReadData( handle ); } /* endwhile */ DosClose( handle ); DosDelete( tempfile ); free( doscl2 ); free( buffer ); return(rc); }
int main(VOID) { STARTDATA SData = {0}; PSZ PgmTitle = "Not in the Window List", /* Title */ PgmName = "CMD.EXE"; /* This starts an OS/2 session */ APIRET rc = NO_ERROR; /* Return code */ PID pid = 0; /* PID returned */ ULONG ulSessID = 0; /* Session ID returned */ UCHAR achObjBuf[100] = {0}; /* Error info if start fails */ STATUSDATA ChildStatus = {0}; /* Child status data */ SData.Length = sizeof(STARTDATA); SData.Related = SSF_RELATED_CHILD; /* A dependent session */ SData.FgBg = SSF_FGBG_FORE; /* start session in foreground */ SData.TraceOpt = SSF_TRACEOPT_NONE; /* No trace */ /* Start an OS/2 session using "CMD.EXE /K" */ SData.PgmTitle = PgmTitle; SData.PgmName = PgmName; SData.PgmInputs = "/K"; /* Keep session up */ SData.TermQ = 0; /* No termination queue */ SData.Environment = 0; /* No environment string */ SData.InheritOpt = SSF_INHERTOPT_SHELL; /* Inherit shell's environ. */ SData.SessionType = SSF_TYPE_WINDOWABLEVIO; /* Windowed VIO session */ SData.IconFile = 0; /* No icon association */ SData.PgmHandle = 0; SData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE; SData.InitXPos = 30; /* Initial window coordinates */ SData.InitYPos = 40; SData.InitXSize = 200; /* Initial window size */ SData.InitYSize = 140; SData.Reserved = 0; SData.ObjectBuffer = achObjBuf; /* Contains info if DosExecPgm fails */ SData.ObjectBuffLen = (ULONG) sizeof(achObjBuf); rc = DosStartSession(&SData, &ulSessID, &pid); /* Start the session */ if (rc != NO_ERROR) { printf ("DosStartSession error : return code = %u\n", rc); return 1; } printf("Removing child process from the Window List... \n"); ChildStatus.Length = sizeof(STATUSDATA); ChildStatus.SelectInd = SET_SESSION_NON_SELECTABLE; ChildStatus.BondInd = SET_SESSION_UNCHANGED; rc = DosSetSession(ulSessID, &ChildStatus); if (rc != NO_ERROR) { printf ("DosSetSession error : return code = %u\n", rc); return 1; } printf("\nPress Ctrl-Esc The child is no longer listed.\n"); printf("\nProgram will terminate in 10 seconds...\n"); rc = DosSleep(10000L); /* wait 10 seconds */ return NO_ERROR; }