[comp.sys.next] Routing stdout into a view

wrb@milton.acs.washington.edu (William Barker) (02/10/90)

Here's a NextStep question:

Suppose I have a NextStep app that has some buttons that execute 
shell scripts via a "system" call.  And suppose I want to direct the
output of the scripts into a view in the same app.  How would I go
about routing the shell script output from the console window (where it
goes now) to the view in my app?

I think builddisk does this very thing, so it appears possible.

Pointers are great; code stubbs even better.

Thanks in advance!

Bill Barker
U of Washington
(206) 543-7315

olson@sax.cs.uiuc.edu (Robert Olson) (02/11/90)

In article <1824@milton.acs.washington.edu> wrb@milton.acs.washington.edu (William Barker) writes:
>Here's a NextStep question:
>
>Suppose I have a NextStep app that has some buttons that execute 
>shell scripts via a "system" call.  And suppose I want to direct the
>output of the scripts into a view in the same app.  How would I go
>about routing the shell script output from the console window (where it
>goes now) to the view in my app?

What I'd do is to use popen():

     FILE *popen(char *command, char type)

     The arguments to popen are pointers to null-terminated
     strings containing respectively a shell command line and an
     I/O mode, either "r" for reading or "w" for writing.  It
     creates a pipe between the calling process and the command
     to be executed.  The value returned is a stream pointer that
     can be used (as appropriate) to write to the standard input
     of the command or read from its standard output.

What you do is just watch the file descriptor the popen returns (*) using 
NXAddFD (**) to be notified of new data coming from the pipe. When you get
something new, just stuff it into the view (make it a text object and
that's easy).

--bob

(*) use fileno() to get it 
(**) or something like that - don't have a manual handy

--
Bob Olson			University of Illinois at Urbana/Champaign
Internet: rolson@uiuc.edu	UUCP: {uunet|convex|pur-ee}!uiucdcs!olson
Bob: "Mine has more CC's".  	Dee: "Yes, but mine has more valves!"