ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I m writing a Mini Shell that take a command from the user executes it and supports also I/O redirection + Piping
Due to all ur help, i was able to write the first part (execution) starting with the redirection But i m facing a big problem with the piping !!!!
Can anyone Help me with this part !!!
i m totally stucked, I need some advices, clues ....
Many Thanks
Well I know how to pipe
but the problem is that i donno the correct way to combine my program with the pipe :S
do i have to create child???
Honestly i m in the stage (not able to think) cz i did many researches and i m too confused :'(
I don't think you want popen(3); I'm pretty sure you're looking for pipe(2). And yes, you'll need to fork(2) off a process first. (I'm not revealing too much because this sounds like homework to me; I had to do this in college for a project.)
Normally when you say "redirection" you mean "getting from and sending to a file" using the shell operators <, >, and so on. When people say "pipe" they usually mean "sending output from one program as input to another" using the shell operator |. From what you say, this is what I understand you want; but these are operations that are performed independently. So what do you mean by "joining them together"? If you write the shell with the notions of input streams, output streams, files, and processes, you only need to handle the two operations because any glued-together interaction in the shell should be able to use the same code. Of course, you'd still have to check syntax to make sure that they don't do something like "cat alpha < beta > gamma | cat delta < epsilon > iota".
Reading your previous posts, this looks very much like some project you're trying to do, and I guarantee that if that's the case, you'll get more out of it if you ask your professor and fellow classmates for help. I'm sorry, but I won't give you any straight answers, but I kinda feel bad, so I'll try to set you on the right track for how I would do it. Let's break it down functionally.
Code:
cmd, pipe :: Process
input, output :: File
rec func execStmt(cmd :opt input pipe output) =
return doCmd(cmd, src, dest)
where
src =
if input = nil then stdin else openFile(input)
dest =
if pipe = nil then
if output = nil then stdout else openFile(output)
else
execStmt(pipe, parseNextChunk())
The behavior of parseNextChunk() reads the input and breaks it up into tokens (and somehow magically by the power of this made-up language, transforms them into parameters). It only reads ahead as much as necessary to know what the next step in the shell statement execution is.
doCmd(cmd, src, dest) executes cmd, getting input from src and passing output to dest. doCmd(...) also produces an object that accepts input, so it can be chained recursively.
Last edited by taylor_venable; 11-14-2006 at 08:27 AM.
I m working on z program
i need u to help me in the algorithm and not write the program
I will read ur post and try to figure it out
thanks again
by the way i m not registered in this course as u noticed i ve been asking for this 3 weeks ago, i don't have to submit it
I m just auditing and i m writing this program not to submit it to the instructor....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.