Sponsored Content
Full Discussion: Named pipe hanging?
Top Forums UNIX for Dummies Questions & Answers Named pipe hanging? Post 302893540 by Ditto on Wednesday 19th of March 2014 04:15:07 PM
Old 03-19-2014
Quote:
Originally Posted by Don Cragun
What return code are you trying to capture?
What are you trying to capture in the log file? (What you have seems to want to capture the output from the echo commands, but not the output from the ls command.)
It would seem that:
Code:
#!/bin/ksh

touch test.file

LOG=./tmp.log

echo "Hello world"  >${LOG}  2>&1

ls -ltr test.file

echo "Goodbye world"  >>${LOG}  2>&1

would be much simpler than what you're doing and produce the same results.
I want to display output and stderr to both display and the log file. [edit] sorry, original post forgot to mention display Smilie [/edit]
I need to use tee for that.
I also want to capture the return code of each command (ie echo, ls, cp, whatever). If I use:
<command> 2>&1 |tee -a <log>
then when I check $? I get the return code for tee.

So I found the logic for named pipes, and the above example seemed to work most of the time.
Then I hit this "side case?" Not really sure.

FYI: I did just find something on the web that helped.

Changed my code to this (added the exec), and now it works Smilie
(soo confused. )

Code:
#!/bin/ksh

touch test.file

LOG=./tmp.log
rm -f ${LOG}

PIPE=./tmp.pipe
mkfifo ${PIPE}
trap "rm -f ${PIPE}" EXIT

tee -a ${LOG} < ${PIPE} &

trap "exec 5>&-" EXIT
exec  5>${PIPE}

echo "Hello world"  >${PIPE}  2>&1

ls -ltr test.file

echo "Goodbye world"  >${PIPE}  2>&1

From what I understand, the named pipe thinks that after the ls (or cp, or mv), that I'm all done with it. (this occurs whether I send the output of the ls, cp, or mv to the PIPE or not). By throwing the exec 5>$PIPE in there, it seems to trick it into expecting more input ???
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
PIPE(3) 						     Library Functions Manual							   PIPE(3)

NAME
pipe - two-way interprocess communication SYNOPSIS
bind #| dir dir/data dir/ctl dir/data1 dir/ctl1 DESCRIPTION
An attach(5) of this device allocates two new streams joined at the device end. X/data and x/ctl are the data and control channels of one stream and x/data1 and x/ctl1 are the data and control channels of the other stream. Data written to one channel becomes available for reading at the other. Write boundaries are preserved: each read terminates when the read buffer is full or after reading the last byte of a write, whichever comes first. Written data is buffered in kernel stream blocks. The writer will block once the stream is full, typically after 32768 bytes or 16 writes. The writer will resume once the stream is less than half full. If there are multiple writers, each write is guaranteed to be available in a contiguous piece at the other end of the pipe. If there are multiple readers, each read will return data from only one write. The pipe(2) system call performs an attach of this device and returns file descriptors to the new pipe's data and data1 files. The files are open with mode ORDWR. SEE ALSO
pipe(2) SOURCE
/sys/src/9/port/devpipe.c PIPE(3)
All times are GMT -4. The time now is 05:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy