Re: fl_add_io_callback question

Eric_Kischell@IUS5.IUS.CS.CMU.EDU
Thu, 30 Jan 97 13:17:16 EST

To subscribers of the xforms list from Eric_Kischell@IUS5.IUS.CS.CMU.EDU :

XFormers,

I have an app where all of the supporting "functions" are in the same
process as my app. I want to display those functions' stdout/stderr output in an
Xforms text object(status). The authors of the supporting functions
do NOT want to redirect their standard/error output to a file.
Does anyone have any Xforms code to perform the above?
The following Xforms thread seems close to the functionality desired.

thx in advance
e.-

// legit???
fl_add_io_callback(fileno(stderr), FL_READ, iocallback, 0);

> In a few applications I'm working on, I'd like to have a status window
> (browser) that shows the stdout and stderr from the application. What's
> the best way to do this?

How are you starting the child process?

If you're starting the child process from within your XForms
application, you might be able to use popen(3) to fire off the process
and watch its output by reading from the file that popen(3) hands you.
Get the file descriptor with the fileno(3) macro, hand it to XForms
with fl_add_io_callback(), and you're in business.

If for some reason that's not adequate, you should be able to do the
usual dup(2), fork(2), and exec(2) business [see Stevens, _Advanced
Programming in the UNIX[r] Environment_ or any other UNIX programming
text for details. I think Kernighan and Pike, _The UNIX Programming
Environment_ also covers this subject in some detail, though I find
Stevens a bit easier to follow on this -- it's also a bit more
modern].

If you need to fool the process into "thinking" its communicating with
a terminal, you may need to create a pseudotty (pty), also discussed
at some length in Stevens. This may be necessary if you need to read
and report in a non-buffered manner.

> I can redirect to a file on startup (2>&.tmp) and then run
> fl_add_io_callback and update the browser when the file changes but I'd
> rather avoid the temporary file. It's also CPU intensive to do it this
> way.

I don't know why this would be CPU intensive, since basically you're
just adding another file descriptor to XForms's select() call.

I can't think of any way to grab the output of an already running
process -- if some does know how to do this, I'd be interested to hear
about it.

spl

>
> > In a few applications I'm working on, I'd like to have a status window
> > (browser) that shows the stdout and stderr from the application. What's
> > the best way to do this?
>
>
> If you need to fool the process into "thinking" its communicating with
> a terminal, you may need to create a pseudotty (pty), also discussed
> at some length in Stevens. This may be necessary if you need to read
> and report in a non-buffered manner.
>
> spl
>

A nice Motif implementation of the PTY can be found in David Flanagan's
"MOTIF TOOLS: StreamlinedGUI Design and Programming with the Xmt Library"
(Chap. 21, pp. 425-445: Command-Line input or cli widget) from O'Reilly
& Associates (1994).

The Xmt library, which contains "cli.c", the source codes for Flanagan's Motif PTY, is available for ftp at ftp.uu.net. I am very much interested
in implementing a similar object using the FORMS library, but always get
side-tracked. To the poster: keeps us, well, "posted" of your progress.
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/xforms-archive/