Redirection
Upon posting on my old post this morning I realized I had moved to redirection but was still posting in my piping question. Here is my issue with redirection. I can get it to work and actually write the output of something like ls to a file that I type in. The problem is that once I call ls or whatever command my system hangs up and I have to use CTRL-D to get out. Here is what I have currently
Code:
void shellRedirection(char *buf, int index){ Thanks a bunch |
Well, I can't tell you (as in don't know) what is wrong, BUT I was always under the impression that the point of these exercises is that you're supposed to write the whole thing in C (like the real shell).
Shelling out via system is 'cheating' imho, and definitely not as per the real thing. Of course, I could be wrong. :) |
hehe, yeah eventually the entire shell will be written but as of now the only working functions are the make file system and the ls commands. In the spirit of more thorough testing I decided to write the commands to the system with the intent of later going back and passing it as a command to my personal shell :)
|
What is output supposed to be? If I understand correctly, output is always 1 (the dup2() call never changes the value of the either argument). What you are trying to accomplish may be done by “saving” the file descriptor before duping it. Alternatively, the more commonly-seen approach is simply to fork() prior to the dup2() so the parent retains all its file descriptors, and only the child will be affected by the redirection.
|
All times are GMT -5. The time now is 04:26 AM. |