The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Java with Unix (Redirection + Piping) fluke_perf High Level Programming 3 04-30-2008 08:52 AM
need help with my implementation of cat in bash sanchopansa Shell Programming and Scripting 4 10-18-2006 03:28 AM
Redirection or piping error message mariner Shell Programming and Scripting 2 05-10-2005 12:04 PM
Socket implementation differences charlcy HP-UX 3 05-07-2005 02:54 PM
Shell Implementation clickonline1 UNIX for Dummies Questions & Answers 3 10-02-2001 01:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-19-2006
Registered User
 

Join Date: Nov 2006
Posts: 24
Stumble this Post!
Piping and redirection implementation

To implement the facility of piping and redirection I used the two commands dup, dup2, and strtok for tokenizing the command.
But when I run the command
ls|more
it is not running fine as I have developed it using the dup2 command.
the more command needs the whole buffer at once.

Please help which system call should I use to implement and maintaining the output in a buffer of one command so that it can be used as a input to other command.



Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-19-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Stumble this Post!
You've been told to build pipes without using pipes? Is this homework?
Reply With Quote
  #3 (permalink)  
Old 12-19-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
It is probably homework, but I'm sure you are allowed to use pipes (as in pipe(2)). No one is going to ask for an implementation the pipe system call.
Reply With Quote
  #4 (permalink)  
Old 12-20-2006
Registered User
 

Join Date: Nov 2006
Posts: 24
Stumble this Post!
I am using the pipe command but I am unable to run it successfully
The command like
ls|more

Please help how to implement that piping.
Reply With Quote
  #5 (permalink)  
Old 12-20-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,849
Stumble this Post!
pipe() is a C system call. Use it to program "ls|more"
Reply With Quote
  #6 (permalink)  
Old 12-20-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Stumble this Post!
Quote:
Originally Posted by mobile01
I am using the pipe command but I am unable to run it successfully
Ah. Here are the steps.
  • Call pipe() to create two fd's for the pipe.
  • Call fork() to create a new process.
  • Parent code:
    • Close the reading-end of the pipe, the parent doesn't need it.
  • Child code:
    • Close the writing-end of the pipe, the child doesn't need it.
    • Duplicate the reading-end over standard input.
    • Close the original reading-end of the pipe, leaving only the duplicate.
    • Call exec() to replace this process with whatever program you want to pipe to. It will keep the file descriptors you've given it, in this case, the pipe.
You should now be able to write to the writing end of the pipe in the original process, and have the data be fed into the standard input of the other process.
Reply With Quote
  #7 (permalink)  
Old 12-20-2006
Registered User
 

Join Date: Nov 2006
Posts: 24
Stumble this Post!
Thanks, But I got stuck when the command length is more than 3 pipes. I made that program and is running fine on 3 pipes but more than that my program is not able to handle.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0