Piping - from a file then return to reading from stdin

Piping - from a file then return to reading from stdin

Post by Nathan Neulinge » Fri, 13 May 1994 08:44:32



Is this any way to start a pipe (say to give answers to the first several
prompts for a command) and and then switch over to stdin?

Sortof like a cat file stdin | command type of thing...

-- Nathan

---------------------------------------------------------------

 
 
 

Piping - from a file then return to reading from stdin

Post by Simon Rober » Fri, 13 May 1994 22:20:19



>Is this any way to start a pipe (say to give answers to the first several
>prompts for a command) and and then switch over to stdin?
>Sortof like a cat file stdin | command type of thing...

several commands including cat recognize a hyphen as representing
stdin.   Thus

cat - file | lpr

will allow you to add stdin text to the top of file while printing it.

Simon
--
------------------------------------------------------

                                 (0223) 250127
The Computer College             +44 223 250127

 
 
 

1. read() does not return bytes read from FIFO - pipe.txt [1/1]

I'm trying to use named pipes (FIFOs) on a System V UNIX platform
and I found that read(...) does not return the number of bytes
read from the FIFO, yet it behaves properly for all other types
(files, pipes, etc).  The value read(...) returns in all cases
except an error is 0.  Is this the case on the majority of UNIX
platforms or do some (BSD) actually return the correct number of
bytes.

I have found a solution of sorts in the following pseudocode;

fd = OPEN("FIFO", ...)

READ(fd, msg, 1)

count = 1
FSTAT(fd, ...)

while st_size > 0
   READ( fd, ...)
   count++
   FSTAT(fd, ...)

is this the correct :-( way of doing it or is there a better
solution.  I am actually buffering the input so I do read
512 bytes instead of 1 but the above code is simpler to show.

If anyone can direct me to any source code using named pipes or
give me any of their own solutions I would be very grateful.  I
am new to UNIX programming so if your solutions could be aimed
at the intermediate programmer level.

In addition if anyone knows of any pitfalls or problems that might
come my way from the use of pipes (incompatibilities etc) it would
be helpful.

The solutions should be portable to as many different platforms as
possible.


Thanks in advance

Dave

2. Monitor timing

3. Reading from stdin without RETURN and echo

4. COL 2.3 & host_type

5. read from stdin while reading line by line a file

6. Apache 1.05 Question

7. piped data & 'read' stdin

8. fbackup return code = 1

9. Reading from multiple pipes and stdin

10. How to read chars from keyboard when stdin is coming from pipe (Sun Sparc)

11. read() on pipe returns ESPIPE instead of EINTR

12. csh and stdin from pipes/files

13. Return code of pipe command (not entire pipe)