Re: XForms: Can't get pipes to work right, totally confused.....

Jan Menzel (jan.menzel@gmx.de)
Sat, 21 Aug 1999 23:12:47 +0200

# To subscribers of the xforms list from Jan Menzel <jan.menzel@gmx.de> :

># To subscribers of the xforms list from Jeff PIerce <piercej@preferred.com> :
>
>This isn't really a xforms questions,but it occured during xforms app
>development...
>
>I am working on a xforms mp3 player... I am using mpg123 as the actual
>player, forking it from the app. No problem....
>
>There is a version of mpg123 for interactive use called mpg123m. It is
>included with the tk3play app. mpg123m not only accepts futher commands
>while it is playing, it also gives progress, play time, blocks played,
>etc, will it is running.
>
>tk3play uses it's pipes to send and get data. No problem I thought. Just
>use pipes in C.
>
>Big problems, at least to me....
>
>Pipes don't work like I thought.....
>
>I set up a command line test app to spawn mpg123 and take further
>commands from inut lines and send it to the mpg123m child . No problem.
>I start my app which spawns mpg123m. I then enter 2 0mp3/cobramp3 ( the
>command mpg123 expects to begin playing a file) which is read by my app
>and sent through outPipe[1] to mpg123m. It starts playing and it's
>progress output comes to the screen.
>
>I then add the pipe for the output of the child (mpg123m) to come back
>to the parent...NO GO......
>
>I try a test app and child to get better aquainted with pipes...
>
>I find that if the child wants to send back it HAS to use a write() and
>not puts() or printf().
>
>I find that if the parent writes out pipe[0], it is echoed back to
>pipe[1].
>
>How do you overcome these problems.
>
>How do you turn off the echo between pipes[0] and pipes[1] at the
>parent????
>
>Why is the child not piping back to the parent when it uses puts() or
>printf()??? This means that you cannot get the output of an app piped
>back unless that app dows not use puts()'s and printf()'s.... How can
>tht be quarantied????
>
>I understand that printf() uses streams (FILE *) while write() uses file
>descriptors(integers). But, I thought that printfputs mapped to
>STDOUT_FILENO....
>
Hi,
you have to create two pipes, one per direction, because pipe are
unidirectional. I include some C++ code taken from "jukebox", also an mp3
player front-end, which communicates with the player via pipes to STDIN and
STDOUT. As you can see, two pipes are created, one for receiving, one for
sending. pipe always echos [1] -> [0], so the not needed file descriptors in
the parent part are closed. In the child the sending pipe (parent view) is
connected to STDIN and the receiving to STDOUT using dup2(). Because dup2()
duplicates the file descriptors both send[] and receive[] descriptors from
the pipes are not used anymore and therefor closed.
Hope that helps. Would be nice if your could send me a copy of your
player front-end. the "jukebox" is not maintained anymore :(.
Cheers Jan

PS: C++ code taken from forkplayer.cc from "Sajber jukebox" v1.08.

[...]
#if !defined(_OS_SOLARIS_) && !defined(_OS_SUN_)
if(socketpair(AF_UNIX, SOCK_STREAM, 0, send) < 0)
perror("socketpair");
if(socketpair(AF_UNIX, SOCK_STREAM, 0, receive) < 0)
perror("socketpair");
#else
if (pipe(send) < 0)
perror("pipe");
if(pipe(receive) < 0)
perror("pipe");
#endif

if((fork_pid = fork()) == 0)
{
dup2(send[0], STDIN_FILENO);

::close(send[0]);
::close(send[1]);

dup2(receive[1], STDOUT_FILENO);

::close(receive[0]);
::close(receive[1]);
execlp(abs.data(), rel.data(), NULL);

[...]

exit(FORK_ERROR);
}
::close(send[0]);
::close(receive[1]);
[...]

------------------------------------------------
Jan Menzel | email: jan.menzel@gmx.de
| http://nummer1.saw.rwth-aachen.de
------------------------------------------------

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/