![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| implementing ftp | damn_bkb | IP Networking | 4 | 01-04-2007 02:35 PM |
| Implementing the redirection | mobile01 | High Level Programming | 0 | 11-30-2006 08:39 AM |
| Implementing a shell in C | jacques83 | High Level Programming | 1 | 11-13-2006 07:24 PM |
| need help in implementing simple interactive shell in C | nix1209 | High Level Programming | 2 | 03-15-2006 06:26 AM |
| Implementing Concatenation(cat) | toughguy2handle | High Level Programming | 2 | 09-21-2005 11:10 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Implementing a shell
I'm implementing a shell in C that supports piping, output redirection, and background processing, and a few other commands. I was wondering how I'd go about implementing the output redirection. So, I'd open a file and I'd fork and execute the command. But how would I get stdout into the file? Any help is greatly appreciated.
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Close stdin and then open some other file.
close() open() Both have man pages. |
|
#3
|
||||
|
||||
|
i too have a question on the topic.
how do i read from keyboard if stdin is actually stdout of another program. an example is less/more: keyboard input still works when they're piped. |
|
#4
|
||||
|
||||
|
Quote:
If you type "tty", you will see the name of your controlling terminal. If it is, say, /dev/pty/j2, then you could simply open that file to gain access to the keyboard. But it is a lot of work to get the name of your particular terminal, so there is a second way. In the unix environment, a process with a controlling terminal can open the special file /dev/tty and get their own controlling terminal. This won't work if there is no crontrolling terminal such as with a cron job. Even though there is only one file on the system called /dev/tty, each user that opens it will get his or her own keyboard. However, this may not be a great move to make. Suppose that I have a complicated pipeline of 4 processes. If they all do this at the same time it will be pretty hopeless to get it all straight. And look at all the threads we get where folks need to script the su command and must "expect" to do it. Users tend to dislike programs that do this. |
|
#5
|
|||
|
|||
|
Closing stdin gives me an infinite loop.
|
|
#6
|
|||
|
|||
|
Is there a way to maybe modify the file descriptor table so that I replace stdout with the file I've just opened? How would I access the file descriptor table though?
|
|
#7
|
||||
|
||||
|
Quote:
however, thanks for the reply. |
||||
| Google The UNIX and Linux Forums |