home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
DOSCMD.ZIP
/
DOSCMD.C
< prev
next >
Wrap
Text File
|
1991-06-06
|
2KB
|
85 lines
#define INCL_SHLERRORS
#define INCL_PROGRAMLIST
#define INCL_DOSSESMGR
#define INCL_DOSERRORS
#define INCL_DOSSEMAPHORES
#define INCL_WINSWITCHLIST
#define INCL_WINPROGRAMLIST
#define INCL_WINWINDOWMGR
#define INCL_WINDIALOGS
#define INCL_WINHEAP
#define INCL_WINCOUNTRY
#define INCL_WINHELP
#include <stdio.h>
#include <process.h>
#include <os2.h>
#include <string.h>
#define CCMAXSTRING 330
#define DOS_SESSION 2
void main(int argc, char **argv)
{
USHORT rc = 0;
USHORT result;
char *ptr;
HFILE handle;
HSWITCH dos_switch;
HWND win_handle;
HENUM enum_handle;
SWCNTRL session_ctl;
CHAR cmdstring[CCMAXSTRING];
/* Open the DOS.SYS DD */
if (rc = DosOpen("DOS$",&handle, &result, 0L, 0,0x01,0x20C1, 0L))
exit(rc);
/* Find the DOS box session number */
enum_handle = WinBeginEnumWindows(HWND_DESKTOP);
while(win_handle = WinGetNextWindow(enum_handle)) {
dos_switch = WinQuerySwitchHandle(win_handle,0);
if (dos_switch) WinQuerySwitchEntry(dos_switch, &session_ctl);
if (session_ctl.idSession == DOS_SESSION && dos_switch) break;
}
WinEndEnumWindows(enum_handle);
/* Build the command to execute by putting spaces around each argv */
/* element and separating them with CRs (0x0D). Terminate with 0 */
cmdstring[0] = 0;
argc--;
argv++;
while(argc) {
ptr = *argv;
strcat(cmdstring," ");
strcat(cmdstring,ptr);
strcat(cmdstring," \r");
argv++;
argc--;
}
/* If there is a string and it is not too big */
if (strlen(cmdstring) && (strlen(cmdstring) <= 259)) {
/* Write it to DOS.SYS */
rc = DosWrite(handle, cmdstring, strlen(cmdstring)+1, &result);
printf("Command length = %d\n",strlen(cmdstring)+1);
printf("DOSWRITE rc = %d\n",rc);
/* If it worked, switch to the DOS box */
if (!rc) WinSwitchToProgram(dos_switch);
}
/* Else there ain't a string or it is too big */
else {
rc = -1;
}
/* Tell us how it went */
printf("FINAL rc = %d\n",rc);
}