tee into 2 named pipes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users tee into 2 named pipes
# 1  
Old 12-11-2006
Question tee into 2 named pipes

The following code does not work (zsh, Solaris), but works without the first line (files instead of pipes) Smilie

mkfifo p1 p2
echo "Hello" | tee p1 > p2 &
paste p1 p2

I would high appreciate any help to fix it.
# 2  
Old 12-11-2006
As you probably know, pipes block when you open one end of them until something opens the other end. As it's a redirection, p2 is opened by the shell before tee is even run -- and since the other end isn't open yet, it waits in the background. Our paste commands apparently open files in the order given, so it opens p1 first, which hasn't been opened since the shell's still waiting on p2, and deadlocks.
Code:
tyler@mecgentoo ~/code/sh/fifo $ mkfifo p1 p2
tyler@mecgentoo ~/code/sh/fifo $ echo "Hello" | tee p1 > p2 &
[1] 6368
tyler@mecgentoo ~/code/sh/fifo $ paste p1 p2
deadlocked

If you reverse the order in paste -- paste p2 p1 instead of paste p1 p2 -- then it works.
Code:
tyler@mecgentoo ~/code/sh/fifo $ mkfifo p1 p2
tyler@mecgentoo ~/code/sh/fifo $ echo "Hello" | tee p1 > p2 &
[1] 6351
tyler@mecgentoo ~/code/sh/fifo $ paste p2 p1
Hello   Hello
[1]+  Done                    echo "Hello" | tee p1 > p2
tyler@mecgentoo ~/code/sh/fifo $

# 3  
Old 12-11-2006
Thank you very much!
# 4  
Old 12-11-2006
Sorry,
I tryed to apply it to a little bit more complicated example

mkfifo p1 p2
echo "Hello" | tee p1 > p2 &
paste =(cut -c1-3 p2) p1

and failed again; at this time changing order p1 and p2 in the third line did not save me Smilie(
# 5  
Old 12-11-2006
Quote:
Originally Posted by zzol
paste =(cut -c1-3 p2) p1
What is this supposed to do? Could you mean
paste $(cut -c1-3 p2) p1

Ignoring the deadlock issue, that inner cut would return "Hel". Then you try
paste Hel p1
Do you have a file named "Hel"? You need to clarify what you want to have happen here.

Also I assume that you realize that a simple sed command can handle everything that you seem to be trying...
$ echo Hello | sed 's/\(...\)\(.*$\)/\1 \1\2/'
Hel Hello
# 6  
Old 12-12-2006
Thanks, the line

paste =(cut -c1-3 p2) p1

in zsh returns "Hel Hello", if p1, p2 are files rather than pipes.

What I really need is to use "join" to join 2 text files by the fieild in fixed width position: e.g. to select all lines from zipped file A where field "cut -c30-40 A" exists in file B "cut -c40-50 B" and I'd like to use named pipes to maximize performance. I understand how to make "Hel Hello" using sed or awk, but I think it could be done with paste and tee with two pipes, but can't escape the deadlock.
# 7  
Old 12-12-2006
Hmmm... interesting about zsh. You need to specify stuff like zsh use, not everyone uses zsh to say the least. As for your problem, is file B also zipped? Roughly how many lines in file B?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why cannot have multiple pipes from tee?

why I cannot do this? prog_name | tee logfile | awk /regexp/ | awk /regexp/ I now this is not elegant code, but am intrigued as to why multiple pipes from tee not allowed. (2 Replies)
Discussion started by: euval
2 Replies

2. UNIX for Advanced & Expert Users

Named pipes using MKS Toolkit

I'm not sure whether or not this question really belongs in this forum and will accept rebuke should I have mistakenly put it in the wrong place (hopefully the rebuke will be accompanied by an answer, though) I wish to implement named pipe communication between two process using MKS Toolkit. I... (2 Replies)
Discussion started by: ArndW
2 Replies

3. Shell Programming and Scripting

Temporary named pipes in Hpux Kornshell

Tried the following on Hpux 11.11, using both ksh, and dtksh $diff <(sort file1) <(sort file2) $ ksh: syntax error: `(' unexpected Strange thing is I tried the same command under RHEL5 using ksh 93 and it works fine. Does anyone know if this is possible on HPUX without the use of... (0 Replies)
Discussion started by: fire!
0 Replies

4. Shell Programming and Scripting

How Unix tee to send pipeline output to 2 pipes ?

Hi, I would like to process, filter the same ASCII asynchronous live data stream in more than one pipe pipeline. So the one pipeline should filter out some records using grep key word and more than one pipes pipelines each should grep for another key words, each set seperately for each... (5 Replies)
Discussion started by: jack2
5 Replies

5. UNIX for Dummies Questions & Answers

Named Pipes

hi, i am working on a script for oracle export, m using a parameter file... i want to compress the dump file that is generated.. in my script following is the code i have written. i am not able to generata .gz file mknod /tmp/exp_tesd1_pipe p gzip -cNf... (4 Replies)
Discussion started by: saharookiedba
4 Replies

6. HP-UX

remove named pipes

Hi, Please help me on this. I am creating a named pipe in a kshell script. I am using mkfifo pipe_name command to create the pipe. I want to remove the named pipe after my work is completed. How can i do that. (8 Replies)
Discussion started by: chintapalli001
8 Replies

7. Shell Programming and Scripting

named pipes

How to have a conversation between 2 processes using named pipes? (5 Replies)
Discussion started by: kanchan_agr
5 Replies

8. Shell Programming and Scripting

FIFO named pipes

Hi...Can anyone please guide me on FIFO Pipes in UNIX.I have lerant things like creating fifo pipes,using them for reads and writes etc.I want to know what is the maximum amount of memory that such a pipe may have? Also can anyone guide me on where to get info on this topic from? (1 Reply)
Discussion started by: tej.buch
1 Replies

9. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

10. Shell Programming and Scripting

named pipes

Hi I am having trouble with a script to export individual schemas to tape from an oracle database. Basicaly I need to export each shema through a pipe with compression and store each shema name in a file with the relevant tape marker. (4 Replies)
Discussion started by: truma1
4 Replies
Login or Register to Ask a Question