TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Andrew Clegg
from: Roland Ott
date: 1995-03-13 02:33:50
subject: Re: Pipes in EMX

Hi, Andrew.

 AC> I am having some problems working out how to use anonymous pipes in
 AC> EMX. 
 AC> I want to start a child process and communicate with its stdin and
 AC> stdout. I have looked at popen(), which lets me start it with a pipe
 AC> connected to stdin *or* stdout, but it doesn't seem to be what I want;
 AC> and pipe(), which creates a pipe with two handles (one for reading and
 AC> one for writing) but I can't understand how I am supposed to 'connect'
 AC> this pipe to a process. 
 AC> Can anyone help?

sorry, thats me once again :)

static int inbound[2], outbound[2];

                                         /* installiere Dateiumleitung */
    if (pipe(outbound) < 0)
        crtError("Cannot open outbound pipe for server.");
    dup2(outbound[0], STDIN_FILENO);     /* replace stdin with pipe */
    close(outbound[0]);
    fcntl(outbound[1], F_SETFD, 1);
    if (pipe(inbound) < 0)
        crtError("Cannot open inbound pipe for server.");
    dup2(inbound[1], STDOUT_FILENO);     /* replace stdout with pipe */
    close(inbound[1]);
    fcntl(inbound[0], F_SETFD, 1);

thats all. Communicating with the client works like this:

read(inbound[0], szBuf, sizeof(szBuf)); /* get from client stdout */
write(outbound[1], pszData, strlen(pszData)); /* put into client stdin*/

Eberhard Mattes uses a similar proceeding in his GNU EMACS port (file
'pmterm.c'?).

EMX has an example too (in '/emx/test/pipe.c').

cu/2 Roland

... I program like a MAN.  I use COPY CON PROGRAM.EXE    
--- Blue Wave/Max v2.12 OS/2 [NR]
* Origin: CCWN: Leistung ueberzeugt !!! (2:246/1401)
SEEN-BY: 105/42 620/243 624/50 711/401 409 410 413 430 807 808 809 934 955
SEEN-BY: 712/407 515 628 704 713/888 800/1 7877/2809
@PATH: 246/1401 50 24/999 240/5002 5500 396/1 270/101 105/103 42 712/515
@PATH: 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™.