home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DOSCMD.ZIP / DOSCMD.C < prev    next >
Text File  |  1991-06-06  |  2KB  |  85 lines

  1. #define INCL_SHLERRORS
  2. #define INCL_PROGRAMLIST
  3. #define INCL_DOSSESMGR
  4. #define INCL_DOSERRORS
  5. #define INCL_DOSSEMAPHORES
  6.  
  7. #define INCL_WINSWITCHLIST
  8. #define INCL_WINPROGRAMLIST
  9. #define INCL_WINWINDOWMGR
  10. #define INCL_WINDIALOGS
  11. #define INCL_WINHEAP
  12. #define INCL_WINCOUNTRY
  13. #define INCL_WINHELP
  14.  
  15. #include <stdio.h>
  16. #include <process.h>
  17. #include <os2.h>
  18. #include <string.h>
  19.  
  20. #define CCMAXSTRING 330
  21.  
  22. #define DOS_SESSION          2
  23.  
  24. void main(int argc, char **argv)
  25. {
  26.    USHORT   rc = 0;
  27.    USHORT   result;
  28.    char    *ptr;
  29.    HFILE    handle;
  30.    HSWITCH  dos_switch;
  31.    HWND     win_handle;
  32.    HENUM    enum_handle;
  33.    SWCNTRL  session_ctl;
  34.    CHAR     cmdstring[CCMAXSTRING];
  35.  
  36.    /* Open the DOS.SYS DD */
  37.    if (rc = DosOpen("DOS$",&handle, &result, 0L, 0,0x01,0x20C1, 0L))
  38.       exit(rc);
  39.  
  40.    /* Find the DOS box session number */
  41.    enum_handle = WinBeginEnumWindows(HWND_DESKTOP);
  42.    while(win_handle = WinGetNextWindow(enum_handle)) {
  43.       dos_switch = WinQuerySwitchHandle(win_handle,0);
  44.       if (dos_switch) WinQuerySwitchEntry(dos_switch, &session_ctl);
  45.       if (session_ctl.idSession == DOS_SESSION && dos_switch) break;
  46.       }
  47.    WinEndEnumWindows(enum_handle);
  48.  
  49.    /* Build the command to execute by putting spaces around each argv */
  50.    /* element and separating them with CRs (0x0D).  Terminate with 0  */
  51.    cmdstring[0] = 0;
  52.    argc--;
  53.    argv++;
  54.    while(argc) {
  55.       ptr = *argv;
  56.       strcat(cmdstring,"  ");
  57.       strcat(cmdstring,ptr);
  58.       strcat(cmdstring," \r");
  59.       argv++;
  60.       argc--;
  61.       }
  62.  
  63.    /* If there is a string and it is not too big */
  64.    if (strlen(cmdstring) && (strlen(cmdstring) <= 259)) {
  65.  
  66.       /* Write it to DOS.SYS */
  67.       rc = DosWrite(handle, cmdstring, strlen(cmdstring)+1, &result);
  68.       printf("Command length = %d\n",strlen(cmdstring)+1);
  69.       printf("DOSWRITE rc = %d\n",rc);
  70.  
  71.       /* If it worked, switch to the DOS box */
  72.       if (!rc) WinSwitchToProgram(dos_switch);
  73.       }
  74.  
  75.    /* Else there ain't a string or it is too big */
  76.    else {
  77.       rc = -1;
  78.       }
  79.  
  80.    /* Tell us how it went */
  81.    printf("FINAL rc = %d\n",rc);
  82.  
  83.  
  84. }
  85.