sort < file | head -1 | cat -n
should print 1 line but sometimes it prints both lines as shown below:
myshell: sort < file | head -1 | cat -n
1 This is line 1
myshell: sort < file | head -1 | cat -n
1 This is line 1
myshell: sort < file | head -1 | cat -n
1 This is line 1
2 This is line 2
At this point the prompt doesn't reappear. I do call wait(&status) 3 times. Any suggestions or ideas?
waiting for multiple processes
I'm writing a basic shell that just executes commands through a program (the shell). I've implemented piping, but sometimes I get incorrect output with the same command. For example,
If file has 2 lines.
You probably have a bug in the way you set your STDIN or STDOUT for those processes.
Maybe you are sometimes setting the STDOUT of the "sort" to STDIN of the "cat".
Or actually maybe the "head" process starts before the "sort" (are you using threads?) and so the STDIN is empty, so it terminates before the sort has a chance of sending it's output.
Maybe you are sometimes setting the STDOUT of the "sort" to STDIN of the "cat".
Or actually maybe the "head" process starts before the "sort" (are you using threads?) and so the STDIN is empty, so it terminates before the sort has a chance of sending it's output.
http://www.mildspring.com - developing android games
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement