[comp.unix.questions] pipes and stderr

razdan@chanakya.oakhill.uucp (Anshuman Razdan) (03/17/90)

I have an application in X Windows that takes care of the keyboard
interface thru a text widget.  I go one step further and do the following

I fork the parent process and execlp a shell from the child process doing
the routine closing of stdin and stdout on the child and parent sites so
that the shell can communicate with the application.  This provides me with the
ability to pass the shell commands to the shell itself and saves me from writing 
all that parsing code myself in trying to emulate the shell. This works fine as
the stout from the shell come back to my application and I listen on the stdin on
parent side and so print out the result on the text indow of my application.  What
I described is pretty simple and the usual (unless there is a more sophisticated way
of communicating with the shell and let the user have its full capability).  Any ways,
My problem is how to trap the the stderr coming from the child and direct them to
stdin of the parent.  Since the pipe calls opens only two file pointers and there is 
nothing for the error for say, you type in ls app.c where app.c does not exist.  Right now
the error message just gets printed in the parent window(shell) from where I had the application
started in the first place.

I am using Sun 4.0.3 on a 3/470 if that helps.

Thanx a bunch for anybody who can guide me to a solution on this one.


--

Anshuman Razdan					Motorola
						Sector CAD
Internal: razdan@chanakya			Austin Tx
Internet: razdan@chanakya.sps.mot.com

******************************************************************
*								 *
* PS: All opinions are my own and my employers have their own    *
*   which of course, most probably, in all honesty, as far       *
*   as I know, which sure is a guess, do not coincide with mine. *
*								 *
******************************************************************

klee@wsl.dec.com (Ken Lee) (03/17/90)

In article <RAZDAN.90Mar16160133@chanakya.oakhill.uucp>,
razdan@chanakya.oakhill.uucp (Anshuman Razdan) writes:
> My problem is how to trap the the stderr coming from the child and
direct them to
> stdin of the parent.

Presumably you are using dup() or dup2() to map the child's stdout to
your pipe.  You can do another dup2 to map stderr to the same pipe.
Alternatively, you can open a separate pipe to handle the stderr.  If
you use 2 pipes, you can use select() or XtAppAddInput() on the parent
side to manage them.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee