home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
CALLBOX.ZIP
/
BOXMON.C
next >
Wrap
Text File
|
1989-10-22
|
2KB
|
65 lines
/* A simple DOS box client */
/* P. Fitzsimmons Sun 10-22-1989 06:37:41 */
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <process.h>
#include <fcntl.h>
#include <share.h>
#include <conio.h>
#include <errno.h>
#include "dostalk.h"
#define TRUE 1
#define FALSE 0
extern int far pascal DosSleep(long val);
#pragma comment(lib, "api.lib") /* this is the lib BIND uses. DosSleep() is in there */
void main(void)
{
int hpipe;
static char buf[256];
unsigned bytes, wbytes;
int done = FALSE;
printf("BOXMON is waiting for an OS/2 session to send a command using CALLBOX.\n");
printf("Press ESC to quit.\n");
while(!done){
errno = 0;
DosSleep(100L);
if(!_dos_open(pipe, O_RDWR | SH_DENYNO, &hpipe)){
_dos_write(hpipe, ackmsg1, sizeof(ackmsg1), &wbytes);
if(!_dos_read(hpipe, buf, sizeof(buf), &bytes)){
printf("Read %d, %s\n", bytes, buf);
if( bytes < sizeof(buf) ){
buf[ bytes ] = 0; // make asciiz
printf("Executing: '%s'\n", buf);
system(buf);
/* with some extra work, you could call spawn() instead
* and return the errorlevel back to the os/2 session.
*/
_dos_write(hpipe, ackmsg2, sizeof(ackmsg2), &wbytes);
}
}
_dos_close(hpipe);
}
else{
if( errno != ENOENT && errno != EACCES ){
printf("Could not open %s, %s.", pipe, _strerror(NULL));
done = TRUE;
}
else
printf("Waiting...\r");
}
if( kbhit() )
done = TRUE;
}
}