[net.unix] pipe breaking

goon@lasspvax.UUCP (Jonny Goon) (10/28/85)

References:


                   {}
Hello,
 I am a relatively inexperienced UNIX user, and I would appreciate
 any advice on the following problem:

 I have some rather large data files stored on disk in compacted form.
 I use ccat and a pipe to feed the data file to a plotting program.
 This fortran program accepts the uncompacted data from standard input
 via an unformatted read statement and plots it; it exits from the
 plotting loop when an EOF condition is detected.  At this point I
 want the program to accept input from the keyboard; however, it 
 continues to read from the pipe.  Do you have any advice on how I
 can redirect the input once the EOF is reached?  Thanks for your support.

|----------------------------------------------------------------------------|
|				      J. Goon                                |
|				      Center for Applied Math.               |
|				      Cornell U.                             |
|				      Ithaca, N.Y. 14853                     |
|		  {decvax,ihnp4,cmcl2,vax135}!cornell!amvax!goon (USENET)    |
|                            goon%amvax@CRNLCS.BITNET (Bitnet)               |
|			     goon@amvax.tn.cornell.edu   (ARPANET)           |
|----------------------------------------------------------------------------|

woods@hao.UUCP (Greg Woods) (10/30/85)

>  This fortran program accepts the uncompacted data from standard input
>  via an unformatted read statement and plots it; it exits from the
>  plotting loop when an EOF condition is detected.  At this point I
>  want the program to accept input from the keyboard; however, it 
>  continues to read from the pipe.  Do you have any advice on how I
>  can redirect the input once the EOF is reached?  Thanks for your support.

  This one is not too hard. You can catch the EOF, close unit 5, and then 
reopen it to read from the terminal. The code looks like:

      read(5,end=100) ...
c jumps to statement label 100 when EOF sensed
      ....
 100  close(unit=5)
c  close pipe
      open(unit=5,file='/dev/tty')
c  reopen unit 5 to terminal
      read(5,...
c read from terminal

--Greg
--
{ucbvax!hplabs | allegra!nbires | decvax!noao | mcvax!seismo | ihnp4!noao}
       		        !hao!woods

CSNET: woods@NCAR  ARPA: woods%ncar@CSNET-RELAY

np42pf@sdcc12.UUCP (Pierre Flament) (11/13/85)

The following construct (sub-shell, see sh(1))
will allow redirection of the input to
the terminal after finding the eof without any special code in
the program:

(ccat file;cat) | plotting_program

A ^D should be send to end the keyboard input

levy@ttrdc.UUCP (Daniel R. Levy) (11/18/85)

In article <478@sdcc12.UUCP>, np42pf@sdcc12.UUCP (Pierre Flament) writes:
>The following construct (sub-shell, see sh(1))
>will allow redirection of the input to
>the terminal after finding the eof without any special code in
>the program:
>
>(ccat file;cat) | plotting_program
>
>A ^D should be send to end the keyboard input

Good idea.  Maybe

(ccat file; echo Keyboard input started > /dev/tty; cat -) | plotting-program

would be even better to let the user know when to begin typing (if what
is typed depends on what came out of the program and couldn't necessarily
be typed ahead).
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!ihnp4!ttrdc!levy

thomas@utah-gr.UUCP (Spencer W. Thomas) (11/19/85)

In article <478@sdcc12.UUCP> np42pf@sdcc12.UUCP (Pierre Flament) writes:
>The following construct (sub-shell, see sh(1)) will allow redirection of
>the input to the terminal after finding the eof without any special code
>in the program:
>(ccat file;cat) | plotting_program

Even easier is
cat file - | plotting_program

(see cat(1))
-- 
=Spencer   ({ihnp4,decvax}!utah-cs!thomas, thomas@utah-cs.ARPA)
	"When wrath runs rampage in your heart you must hold still
	 that rambunctious tongue!" - Sappho