TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Ed Becker
from: Craig Morrison
date: 1994-10-05 11:08:00
subject: OS/2 Window

Ed Becker doth sayeth in a message unto All:

EB> I'd also like to go the other way:  I would like to send
EB> anything the program has coming out of stdout and send it to
EB> a pipe.  Peter Fitzsimmons did this with Maxpipe, but going
EB> to a com port if memory serves me correct.  I'd need it from
EB> a PIPE so I could pick it up in another process.

  This should give you some ideas:

 #define INCL_DOSQUEUES   /* Queue values */
 #include 

 #define PIPESIZE 256
 #define HF_STDOUT 1      /* Standard output handle */

 HPIPE hpR, hpW;
 RESULTCODES resc;
 ULONG cbRead, cbWritten;
 CHAR achBuf[PIPESIZE], szFailName[CCHMAXPATH];

 HFILE hfSave = -1,
       hfNew = HF_STDOUT;

 DosDupHandle(HF_STDOUT, &hfSave);    /* Saves standard output handle      */

 DosCreatePipe(&hpR, &hpW, PIPESIZE); /* Creates pipe                      */

 DosDupHandle(hpW, &hfNew);           /* Duplicates standard output handle */

 DosExecPgm(szFailName, sizeof(szFailName),   /* Starts child process      */
            EXEC_ASYNC, (PSZ) NULL, (PSZ) NULL, &resc,
            "DUMMY.EXE");

 DosClose(hpW);                       /* Closes write handle to ensure     */
                                      /* Notification at child termination */

 DosDupHandle(hfSave, &hfNew);        /* Brings stdout back                */

   /*
    * Read from the pipe and write to the screen
    * as long as there are bytes to read.
    */

   do {
       DosRead(hpR, achBuf, sizeof(achBuf), &cbRead);
       DosWrite(HF_STDOUT, achBuf, cbRead, &cbWritten);
   } while(cbRead);


 The parent process can also use unnamed pipes to communicate with a child
process by redirecting both the standard input and the standard output for
the child process. To do this, the parent process:

  1. Uses DosDupHandle to redefine the read handle of one pipe as standard
     input (0000), and the write handle of the other pipe as standard
     output (0001).

  2. Starts the child process with DosExecPgm.

  3. Uses the remaining pipe handles to read and write to the pipes.

 The parent process controls the meanings for standard I/O for the child
process. Thus, when the child process uses standard I/O handles with
DosRead and DosWrite, it reads from and writes to the pipes of its parent
instead of reading from the keyboard and writing to the display.

 See ya,

Craig
cam{at}wpc.cioe.com

... A closed mouth catches no feet

--- timEd/2-B9

* Origin: Workplace Connection * (317) 742-2680 * (1:201/60)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413
SEEN-BY: 711/430 807 808 809 934 942 712/353 623 713/888 800/1
@PATH: 201/60 1 3615/50 229/2 12/2442 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.