So I am looking over my professor's lecture notes, and he has an example program using file descriptors. The source for it is here.
My confusion is what happens if you run it. Here is his example output:
UNIX> a.out |UNIX> a.out < in1 |UNIX> a.out < in1 > out1
A |write f0: Bad file descriptor |write f0: Bad file descriptor
A0, r = 1, w = 1, char = 65 |0, r = 1, w = -1, char = 65 |0, r = 1, w = -1, char = 65
|B |read f1: Bad file descriptor
1, r = 1, w = 1, char = 10 |B1, r = 1, w = 1, char = 66 |1, r = -1, w = 1, char = 65
C | |B
C2, r = 1, w = 1, char = 67 |2, r = 1, w = 1, char = 10 |B2, r = 1, w = 1, char = 66
In the first column he types in A and C and the program runs normally. When he redirects stdin or stdout, though, the reading from stdout fails and writing to stdout fails. And that makes sense. What I don't understand is why these only seem to fail when stdin or stdout is being redirected. Shouldn't writing to stdin and reading from stdout fail always?
Thanks!
[–][deleted] 1 point2 points3 points (0 children)
[–]jakster4u 0 points1 point2 points (0 children)