Named pipe hanging?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Named pipe hanging?
# 8  
Old 03-19-2014
You'd use a named pipe only to send the output of the preceding pipeline to another command as the below lines of shell code show...
Code:
mkfifo somepipe   # create a named pipe
wc -l < somepipe &   # start a reader process
ls -ltr | tee somepipe | grep "some_file_name"   # pipe output of "ls -ltr" to "grep" via tee and to "wc -l" via somepipe

but the stuff you're trying to do doesn't need a fifo and I'd go with what Don Cragun suggests...
# 9  
Old 03-19-2014
Quote:
Originally Posted by Ditto
- want to capture stdout and sterr to both display and log file
- need to capture the return code of the command as well (ie $?)
Is it okay if the streams are merged before they're printed, or does stderr still need to be redirected outside the script?
# 10  
Old 03-19-2014
Quote:
Originally Posted by shamrock
You'd use a named pipe only to send the output of the preceding pipeline to another command as the below lines of shell code show...
Code:
mkfifo somepipe   # create a named pipe
wc -l < somepipe &   # start a reader process
ls -ltr | tee somepipe | grep "some_file_name"   # pipe output of "ls -ltr" to "grep" via tee and to "wc -l" via somepipe

but the stuff you're trying to do doesn't need a fifo and I'd go with what Don Cragun suggests...
wc -l < somepipe & will hang in a shell, while wc -l somepipe & will not... The difference is subtle but important: One tells wc -l to open the pipe, which happens after it's run and backgrounded. The other tells the shell to open the pipe, which happens before it's run and backgrounded.
# 11  
Old 03-19-2014
Quote:
Originally Posted by Corona688
wc -l < somepipe & will hang in a shell, while wc -l somepipe & will not... The difference is subtle but important: One tells wc -l to open the pipe, which happens after it's run and backgrounded. The other tells the shell to open the pipe, which happens before it's run and backgrounded.
Nope...the only difference is that wc -l somepipe & will give the no. of line plus the filename whereas wc -l < somepipe & will give the no. of lines in the ls -ltr listing...that is just the way wc -l works...
This User Gave Thanks to shamrock For This Post:
# 12  
Old 03-19-2014
Interesting... I'm guessing the strange hangs I've had trying to do that with stdin/stdout are effects of backgrounding something talking to the terminal, then.
# 13  
Old 03-19-2014
Quote:
Originally Posted by Corona688
Interesting... I'm guessing the strange hangs I've had trying to do that with stdin/stdout are effects of backgrounding something talking to the terminal, then.
I tested your and my versions and that is the only difference I saw...
# 14  
Old 03-19-2014
Quote:
Originally Posted by Corona688
Interesting... I'm guessing the strange hangs I've had trying to do that with stdin/stdout are effects of backgrounding something talking to the terminal, then.
Probably. & implies a subshell.

Regards,
Alister
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to test named pipe file?

Hi ALL, How can I test a given file name exists and if it is a named pipe file in shell script ? Thanks............ (2 Replies)
Discussion started by: mycode.in
2 Replies

2. Programming

Named pipe behavior in Linux

Hi All ! I try to collect importent events from syslog and in my syslog conf, there is something like this: *.* |/logs/ipes/SLpipe1 I have a program, which opens this pipe and reads the messages from it. But how this pipe works ? Where can I probably read something about the details,... (3 Replies)
Discussion started by: mabra
3 Replies

3. Shell Programming and Scripting

Named pipe performance

Hi, I am getting data into a Named pipe. Does Named pipe have any size restriction; I know it does not have any storage and it just passes on the data to the next process. I want to know, if there will be a difference in the Named pipe performance if the data input is more. (I am using DB2... (1 Reply)
Discussion started by: sudvishw
1 Replies

4. Shell Programming and Scripting

Using Named pipe in shell script

Hi, I want to use a Named pipe to get input from a growing file for further processing. When I prototype this scenario using a while loop, the data is not written to the named pipe. This the script I use to get data into the Named pipe: #!/bin/ksh mkfifo pipe while (( n <= 10 )) do echo... (2 Replies)
Discussion started by: sudvishw
2 Replies

5. Shell Programming and Scripting

pipe to file named with date

I would like to pipe (redirect ? - what is the right term?) the output of my script to a file named with the current date. If I run this at a command prompt: date +'%Y%m%d" ...it returns "20110429" OK, that's good... so I try: ./script.sh > "'date +%Y%m%d'.csv" I get a file... (1 Reply)
Discussion started by: landog
1 Replies

6. UNIX for Dummies Questions & Answers

Filtering mail into a named pipe

Hello, On my machine, all mail is stored in my /var/spool/mail. IS there a way to direct all mail that goes there into a namep pipe? Thank you, Dado (4 Replies)
Discussion started by: dadoprso
4 Replies

7. UNIX for Dummies Questions & Answers

Named Pipe contents to a file

I want to copy the contents of a named pipe to a file. I have tried using: cat pipe.p >> transcript.log but I have been unsuccessful, any ideas? (4 Replies)
Discussion started by: carl_vieyra
4 Replies

8. UNIX for Dummies Questions & Answers

Named PIPE

Gurus, I've a File Transaction Server, which communicates with other servers and performs some processing.It uses many Named PIPE's. By mistake i copied a named PIPE into a text file. I heard that PIPE files shouldn't be copied.Isn't it? Since it's a production box, i'm afraid on... (2 Replies)
Discussion started by: Tamil
2 Replies

9. Programming

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666) func. It then opens the pipe using open func - fd = open... (2 Replies)
Discussion started by: sharanbr
2 Replies

10. UNIX for Advanced & Expert Users

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666);) func. It then opens the pipe using open func - fd =... (1 Reply)
Discussion started by: sharanbr
1 Replies
Login or Register to Ask a Question