[comp.unix.wizards] Where to send the data

snoopy@sopwith.UUCP (Snoopy) (05/30/89)

In article <17659@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:

| Programs that produce output should produce the output to stdout.  If
| they will rarely be used to write to anything but the spooler, they
| should be given a less-accessible name and the program the user runs
| should be a shell script:
|
|	real-pspen < plot.data | lpr -Pfoo

Sounds good so far.  Next question: what should a program do if it wants
to generate (1) output for a graphics device, (2) possible interaction
with the user, and (3) error messages.

I am currently developing such a program (adding extensions to ghostscript).
Currently, the program opens the device directly and talks to the user
via stdout.  Error messages naturally go to stderr as God intended.  :-)
I am not entirely happy with the program 'knowing' where to send the
graphics output.  The printer case isn't toooo bad, it just opens
/dev/printer which is a link to whatever port the printer is hooked to.
If you need to use a spooler,just have it fork a process, exec the spooler,
and ship the data down a pipe.  Using a graphics window on the CRT display
isn't as clean, as there are multiple choices for which window to use.
It is also desirable to be able to redirect the graphics output into a
regular disk file for debugging purposes, or through a filter program.

Possibilities:

	- use /dev/tty for the user interaction.  But this can also
	  be used in batch mode, so what if there isn't a tty associated
	  with the process?  Doesn't allow redirecting the user interaction.

	- use stderr for both user interaction and errors.  Boo hiss.

	- send the graphics output to fd 3 and always remember to
	  redirect fd 3 on the command line.  Fail if fd 3 isn't
	  already open.  If fd 3 *is* already open but not set to the
	  right place, some lucky file gets a big surprise.

	- send graphics output to stdout.  Send user interaction to
	  fd 3 if it is open.  If fd 3 isn't open, attempt to open /dev/tty.
	  If that fails, send nastygram to stderr and fail.

	- add a command option to set where the output goes, like cc(1).

None of these seem really clean and aesthetically pleasing.  :-(
Ideas/comments/improvements/suggestions welcome.
Auxout would be ideal for this, if it existed.  (I was thinking of
things like cpio/tar when I suggested it.)
    _____     						  .-----.
   /_____\    Snoopy					./  RIP	 \.
  /_______\   qiclab!sopwith!snoopy			|  	  |
    |___|     parsely!sopwith!snoopy			| tekecs  |
    |___|     sun!nosun!illian!sopwith!snoopy		|_________|