🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #2161

Re: Talking to a DOS box from OS/2 2.0

#2161
From: Karen Bench
Date: Mon, 28 Sep 1992 05:27
152 lines
5028 bytes

>>>> From: dmm@vnet.ibm.com (Dave Mooney)
>>>> Subject: Re: Talking to a DOS box from OS/2 2.0
>>>> Lines: 18
>>>> 
>>>> In <589@ddbeezer.Dundee.NCR.COM> Tim Craig writes:
>>>> > Can someone who has digested the wads of OS/2 2.0 doc please inform me
>>>> > if there is any method of communicating between an OS/2 process and
>>>> > something in a DOS box. I know this can be done via the clipboard but I
>>>> > was hoping for something a little more flexible (along the lines of pipes
>>>> > or even DDE as is possible between Windows and OS/2). Any ideas, pointers
>>>> > or references?
>>>> 
>>>> Create a named pipe on the OS/2 side, open up this pipe as a normal file
>>>> on the DOS side, and use the usual DOS I/O functions to read and write
>>>> this pipe.
>>>> 
>>>> dave
>>>> 
>>>> -------------------------------------------------------------------------
>>>> Dave Mooney                                              dmm@vnet.ibm.com
>>>>  C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario

  I have been trying to do this too and have not been
  completly successful. I can read chars in the dos box that have 
  been put in the named pipe as long as there are chars to read but 
  HOW DO I TELL WHEN there are characters available. When the 
  dos program goes to read the pipe and there are no chars available
  to read, the dos program waits (blocks?) for them to become available,
  but in my application they won't become for some period of time, and
  I can't just sit there and wait. I have tried feof, bits in the file 
  handle, ioctl function call and they don't indicate if there are
  bytes to read. I am using the NO_WAIT option and byte pipe mode 
  on the  os/2 pipe open which I thought should make the fgetc in the
  dos task return when no chars are there.
 
  If anyone knows how to do this please mail me.
  Thanks

  Here is the code I am using.

/* os/2 part compile with ibm c 1.0 as follows: icc pipeos2.c */
#define INCL_DOS
#define INCL_DOSNMPIPES
/* includes and variables */
#include <os2.h>
#include <stdlib.h>
#include <string.h>

  HPIPE  Handle;
  ULONG  outbuffer, inbuffer, timeout, BytesToWrite, BytesWriten;
  USHORT rc;

  ULONG BytesWriten;

  char  temp_buf[25];


main(argc, argv, envp)
int argc;
char *argv[];
char *envp[];
{

    outbuffer = 5000;
    inbuffer = 5000;
    timeout = 0;
    rc = DosCreateNPipe("\\PIPE\\TWO",    /* create pipe */
             &Handle,
             NP_WRITEBEHIND | /* was set to nowritebehind */
               NP_INHERIT | 
               NP_ACCESS_DUPLEX,
               NP_NOWAIT | 
               NP_TYPE_BYTE |
               NP_READMODE_BYTE |
             1, /* only 1 of this pipe */
             outbuffer,
             inbuffer,
             timeout);

    printf("Return from DosCreateNPipe=%d\n", rc);

    do 
    {
        rc = DosConnectNPipe(Handle);
    }while (rc != 0);

    printf("Msdos task connected to Pipe two\n");

    
    temp_buf[0] = 't';
    temp_buf[1] = 'e';
    temp_buf[2] = 's';
    temp_buf[3] = 't';
    BytesToWrite = 4;
    rc = DosWrite(Handle,
          (PVOID)temp_buf,
          BytesToWrite,
          &BytesWriten);

    printf("Return from DosWrite=%d  BytesWriten=%ld\n", rc, BytesWriten);
    /* sit here and spin, msdos task will try to read pipe contents */
    while(1)
        ;

}
   
   
  
/* The dos part ===================================================== */
/* msdos part compile with BorlandC 3.x as follows: bcc dos1.c */

#include <stdio.h>    /* for fopen, printf */
#include <process.h>  /* for exit */
#include <dos.h>      /* for delay */

int ch1, ch2, ch3, ch4, ch5;
FILE *pipe_handle;
void main()
{
    pipe_handle = fopen("\\PIPE\\TWO", "rb");
    if(pipe_handle)
        printf("Msdos open of pipe TWO ok\n");
    else
    {
        printf("Couldn't open pipe \n");
        exit(0);
    }

    delay(2000); /* 2 second delay to allow time for os/2 task to */
                 /* write pipe */

    ch1 = fgetc(pipe_handle);
    printf("ch1=%c\n", ch1);
    ch2 = fgetc(pipe_handle);
    printf("ch2=%c\n", ch2);
    ch3 = fgetc(pipe_handle);
    printf("ch3=%c\n", ch3);
    ch4 = fgetc(pipe_handle);
    printf("ch4=%c\n", ch4);

    printf("before ch5 = fgetc(pipe_handle\n");
    /* !!!!!!!!!!!!   hangs here !!!!!!!!!!!!!!!!!!!!!! */
    /* stop the os2 task that handles the pipe and the  */
    /* next line will complete with an error */
    ch5 = fgetc(pipe_handle);
    printf("after ch5 = fgetc(pipe_handle\n");
    printf("ch5=%d\n", ch5);


}
Technical Details
Message-ID: <1992Sep28.052736.5590@tijc02.uucp>
Path: arc1-ca.pugleaf.net!sparky!uunet!tijc02!kcc056

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!tijc02!kcc056
From: kcc056@tijc02.uucp (Karen Bench)
Subject: Re: Talking to a DOS box from OS/2 2.0
Message-ID: <1992Sep28.052736.5590@tijc02.uucp>
Organization: Siemens Industrial Automation, Johnson City TN
Distribution: net
Date: Mon, 28 Sep 92 05:27:36 GMT
Lines: 152