The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fifo or named pipe working? lvkchaitanya UNIX for Dummies Questions & Answers 1 02-06-2008 12:44 PM
Pipe data to shell script tomjones07 Shell Programming and Scripting 3 03-14-2007 07:50 PM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 08:27 AM
PIPE and FIFO buffer size Jus UNIX for Advanced & Expert Users 1 08-20-2004 03:53 PM
Pipe & fifo.... M3xican High Level Programming 4 07-20-2002 07:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2007
victorin victorin is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
Reading from blocking fifo pipe in shell script

Hi!!

I have a problem reading from a fifo pipe in shell script.

The idea is simple, I have a C program with two pipe files:
  • An input pipe I use to send commands in shell script to the C program (echo "command" > input.pipe)
  • An output pipe that I read the result of the command also in shell script (cat output.pipe)

The problem is in the cat output.pipe
After output the data the cat process remains blocked (like a "tail -f") waiting for data.

It's possible to avoid this state?? (It's possible the cat terminates when the pipe not contains more data? Something like non-blocking read)

Thank you very much
  #2 (permalink)  
Old 05-07-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
cat is waiting for input from the keyboard, enter CTRL+D to close it.

Regards
  #3 (permalink)  
Old 05-08-2007
victorin victorin is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
Thx Franklin, your solution works in console mode, but I'm looking for a clean scripting solution.

Any ideas?
  #4 (permalink)  
Old 05-08-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Consider what "echo "command" > input.pipe" does. It opens the pipe, writes some data, and then closes the pipe. Your C program needs to do likewise. For each command, it must open the output pipe, write some data, and then close the pipe. This close will cause your cat process to encounter eof of its side of the pipe and then it will exit.
  #5 (permalink)  
Old 05-08-2007
victorin victorin is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
Thank you to all,

The solution I found is to write a little C wrapper software that makes non-blocking read to the pipe (with the flag O_NONBLOCK)

When all the avaliable data is read, the program terminates itself

Thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0