home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / OS2.BAT < prev    next >
DOS Batch File  |  1994-08-13  |  5KB  |  154 lines

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