home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HomeWare 14
/
HOMEWARE14.bin
/
os2
/
cenv2_19.arj
/
DOSSLAVE.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-03-08
|
3KB
|
95 lines
@echo OFF
REM **************************************************************
REM *** DosSlave - This CEnvi tool works with OS2.BAT to allow ***
REM *** ver.1 DOS sessions to perform OS/2 command. This ***
REM *** portion runs in the background to service ***
REM *** requests from DOS sessions. ***
REM **************************************************************
start "DOS Slave" /N /FS /B CEnvi.exe %0.CMD
WINSET "DOS Slave" HIDE
GOTO CENVI_EXIT
#include <FileIO.lib>
#include <NamePipe.lib>
PipeName = "\\PIPE\\DOSSLAVE.IN"
PipeHandle;
// Open the pipe for reading
rc = DosCreateNPipe(PipeName,PipeHandle,
NP_ACCESS_DUPLEX | NP_NOINHERIT,
NP_WAIT | NP_TYPE_BYTE | NP_UNLIMITED_INSTANCES | NP_READMODE_BYTE,
4000, 4000, 0)
if ( rc )
printf("Error %d opening named pipe.\a\n",rc), abort();
for ( ; ; ) {
InstructionFile = GetInputFromDOS();
fp = fopen(InstructionFile,"rt");
if ( NULL == fp )
printf("Unable to open file \"%s\".\n\a",InstructionFile), abort();
DoDirectory = fgets(fp);
DoCommand = fgets(fp);
// get rid of line feed ending DoDirectory and DoCommand
fclose(fp);
DoDirectory[strlen(DoDirectory)-1] = 0;
DoCommand[strlen(DoCommand)-1] = 0;
// determine if piping wanted to be seen
if ( memicmp("SEE ",DoCommand,4) ) {
// do it without capturing to a file
printf("\n%c: & cd %s & %s\n",DoDirectory[0],DoDirectory+2,DoCommand);
system("%c: & cd %s & %s",DoDirectory[0],DoDirectory+2,DoCommand);
} else {
// wants to see results
// output directory is same as input, but with different extension
strcpy(OutputFile,InstructionFile);
strcpy(OutputFile + strlen(OutputFile) - 2,"OUT");
// Send cmd.exe command to do directory, then perform command
printf("\n%c: & cd %s & %s\n",DoDirectory[0],DoDirectory+2,DoCommand+4);
system("%c: & cd %s & %s > %s",DoDirectory[0],DoDirectory+2,DoCommand+4,OutputFile);
}
DeleteForever(InstructionFile);
}
DeleteForever(FileSpec) // delete file with no chance of undeleting
{
// Delete the input file (without wasting DELDIR space)
if defined(DELDIR)
strcpy(SaveDeldir,DELDIR), undefine(DELDIR);
system("del %s",FileSpec);
if ( defined(SaveDeldir) )
strcpy(DELDIR,SaveDeldir), undefine(SaveDeldir);
}
GetInputFromDos()
{
rc = DosConnectNPipe(PipeHandle);
if ( rc ) {
printf("Error %d connecting pipe\n",rc);
abort();
}
CommandLength = 0;
do {
rc = DosRead(PipeHandle,InChar,1,CharReadCount);
if ( rc || 1 != CharReadCount ) {
printf("\nDosRead error rc = %d, CharReadCount\a\n",rc,CharReadCount);
abort();
}
Input[CommandLength++] = InChar[0];
} while( '\n' != InChar[0] );
DosDisconnectNPipe(PipeHandle);
Input[CommandLength-2] = '\0';
return( Input );
}
:CENVI_EXIT