Handling I/O redirections in my shell.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2007
Posts: 17
Reputation: Sebouh is an unknown quantity at this point 
Solved Threads: 0
Sebouh Sebouh is offline Offline
Newbie Poster

Handling I/O redirections in my shell.

 
0
  #1
Apr 11th, 2007
Hi all.
This is my first post here, and i need urgent help with a programming assignment.
I am working on an assignment which requires me to build a simple shell. My shell must handle simple commands with arguements and ones with piping and I/O redirection.
The problem is i have no idea how to implement this redirection. The shell does alot of other things. I'm only stuck at this!
To further explain, my program reads the user's input such as: "ls -1 > text.txt" and does what a normal shell does. The problem is redirecting one's output as an input and the reverse. I have to execute two of the commands by forking two children and execve-ing. Then i need to do the redirection thing.
I have no idea were to start. I suppose it has to do with piping? I'm not sure.

Thanks alot for your help!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Handling I/O redirections in my shell.

 
0
  #2
Apr 11th, 2007
Interesting.. I don't know the answer to your question.
In Java though you have a way to get a handle to the Input and Output streams of a child process you've forked.. So I'm sure it would be possible in C as well.. will check.. Do post the answer if you get it..
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Handling I/O redirections in my shell.

 
0
  #3
Apr 11th, 2007
I think you could use freopen to do it somehow... I'm not sure that it'll work, but hopefully it'll at least be a starting point.
Originally Posted by man freopen
The freopen() function opens the file whose name is the string pointed to by path and associates the stream
pointed to by stream with it. The original stream (if it exists) is closed. The mode argument is used just as
in the fopen() function. The primary use of the freopen() function is to change the file associated with a
standard text stream (stderr, stdin, or stdout).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC