home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / OS2.BAT < prev    next >
DOS Batch File  |  1995-07-28  |  5KB  |  157 lines

  1. @echo off
  2. REM ********************************************************
  3. REM *** OS2.bat - Just like OS/2's command, except       ***
  4. REM *** ver.3     runs from a DOS VDM under OS/2.        ***
  5. REM ***           This batch file requires CEnviD for DOS ***
  6. REM ********************************************************
  7.  
  8. REM **************************************************************
  9. REM *** Build an environment variable to hold all of the input ***
  10. REM *** parameters so they can all be passed to the OS/2       ***
  11. REM *** command in the same way they appear here               ***
  12. REM **************************************************************
  13. SET OS2PARM=%1
  14. :PARM_LOOP
  15.    SHIFT
  16.    IF _%1_ == __ GOTO END_PARM_LOOP
  17.    SET OS2PARM=%OS2PARM% %1
  18.    GOTO PARM_LOOP
  19. :END_PARM_LOOP
  20.  
  21. REM **************************************************
  22. REM *** THE FOLLOWING IS CEnviD CODE TO EXECUTE DOS ***
  23. REM *** INTERRUPT FOR STARTING AN OS2 SESSION      ***
  24. REM **************************************************
  25. CEnviD OS2.BAT
  26. GOTO CENVI_EXIT
  27.  
  28. main()
  29. {
  30.    if !defined(OS2PARM)
  31.       Instructions();
  32.    else {
  33.       if ( defined(DELDIR) ) {
  34.          // keep temporary files from wasting time
  35.          strcpy(RememberDelDir,DELDIR);
  36.          undefine(DELDIR);
  37.       }
  38.       OS2Command(OS2PARM);
  39.       if ( defined(RememberDelDir) )
  40.          DELDIR = RememberDelDir;
  41.    }
  42. }
  43.  
  44. Instructions()
  45. {
  46.    puts("\a")
  47.    puts(``)
  48.    puts(`OS2.BAT - EXECUTE OS/2 COMMAND FROM A DOS SESSION`)
  49.    puts(` `)
  50.    puts(`SYNTAX: OS2 [SEE] Command [parameters]`)
  51.    puts(``)
  52.    puts(`WHERE:`)
  53.    puts(`  SEE - Wait for command to finish, and "SEE" OS/2 output on this screen`)
  54.    puts(`  Command - Any OS/2 session command`)
  55.    puts(`  parameters - Parameters to pass to the OS/2 command`)
  56.    puts(``)
  57.    puts(`EXAMPLES: OS2 SEE chkdsk c:`)
  58.    puts(`          OS2 START "XCOPY A-B" /FS XCOPY A:\ B:`)
  59.    puts(``)
  60.    puts(`NOTE: OS2.BAT requires CEnviD for DOS`)
  61.    puts(``)
  62. }
  63.  
  64. OS2Command(pCommand)
  65. {
  66.    // determine if want to SEE output, and if so then output
  67.    // file name
  68.    if ( !strnicmp(pCommand,"SEE",3) && isspace(pCommand[3]) ) {
  69.       pCommand += 4;
  70.       // make temporary text output file in temp directory,
  71.       // else current directory
  72.       if ( defined(TEMP) )
  73.          strcpy(TempDir,TEMP)
  74.       else if ( defined(TMP) )
  75.          strcpy(TempDir,TMP)
  76.       else
  77.          TempDir = ".";
  78.       TempDir = FullPath(TempDir);
  79.       if ( !stricmp(TempDir+1,":\\") ) TempDir[2] = 0;
  80.       srand();
  81.       sprintf(SeeFile,"%s\\~OS2%04X.TMP",TempDir,rand());
  82.       if ( Directory(SeeFile) )
  83.          system("del %s",SeeFile);
  84.    } else {
  85.       SeeFile = NULL;
  86.    }
  87.  
  88.    StartData = BuildStartData(pCommand,SeeFile);
  89.    reg.ah = 0x64;
  90.    reg.bx = 0x25;    // API ordinal
  91.    reg.ch = 'c', reg.cl = 'l';
  92.    reg.ds = segment(StartData);
  93.    reg.si = offset(StartData);
  94.    interrupt(0x21,reg);
  95.    GiveUpTimeSlices(1500);
  96.  
  97.    if ( SeeFile ) {
  98.       // wait for file to exist
  99.       while ( !Directory(SeeFile) ) {
  100.          GiveUpTimeslices(500);
  101.       }
  102.       // file writing is finished when we can open it
  103.       while ( !(fp = fopen(SeeFile,"rt")) ) {
  104.          GiveUpTimeslices(500);
  105.       }
  106.       fclose(fp);
  107.       system("type %s",SeeFile);
  108.       system("del %s",SeeFile);
  109.    }
  110. }
  111.  
  112. GiveUpTimeSlices(pMilliSecondWait)
  113. {
  114.    lMicroSecond = pMilliSecondWait * 1000;
  115.    reg.ah = 0x86;
  116.    reg.cx = (lMicroSecond >> 16) & 0xFFFF;
  117.    reg.dx = lMicroSecond & 0xFFFF;
  118.    interrupt(0x15,reg);
  119. }
  120.  
  121.  
  122. gProgramArgs;
  123. gOS2DeamonName = "DOS Slave";
  124.  
  125. BuildStartData(pCommand,pSeeFile)
  126. {
  127.    BLObPut(sdata,0,UWORD16);  // size of structure, add later
  128.    BLObPut(sdata,0,UWORD16);  // independent process
  129.    BLObPut(sdata,1,UWORD16);  // background
  130.    BLObPut(sdata,0,UWORD16);  // no trace
  131.    BLObPut(sdata,pointer(gOS2DeamonName),UWORD32);
  132.    BLObPut(sdata,NULL,UWORD32);  // NULL program to execute
  133.  
  134.    // build global program args; first change to directory then
  135.    // run start commmand
  136.    CurDir = FullPath(".");
  137.    sprintf(gProgramArgs,"/C %c: & CD %s & %s",CurDir[0],CurDir+2,pCommand);
  138.    if ( pSeeFile ) {
  139.       strcat(gProgramArgs," > ");
  140.       strcat(gProgramArgs,pSeeFile);
  141.    }
  142.    BLObPut(sdata,pointer(gProgramArgs),UWORD32);
  143.    BLObPut(sdata,0,UWORD32);  // TERMQ
  144.  
  145.    BLObPut(sdata,0,UWORD32);  // pointer to environment
  146.    BLObPut(sdata,0,UWORD16);  // No inheritance
  147.    BLObPut(sdata,1,UWORD16);  // Full screen
  148.  
  149.  
  150.    // go back and add size
  151.    BLObPut(sdata,0,BLObSize(sdata),UWORD16);
  152.    return sdata;
  153. }
  154.  
  155. :CENVI_EXIT
  156. SET OS2PARM=
  157.