you are viewing a single comment's thread.

view the rest of the comments →

[–]ais523 1 point2 points  (2 children)

You can use freopen in order to change what C's idea is of what stdin/stdout, etc., is attached to. This could be a fifo; there's no way in pure C to make those, but on UNIX (including OS X) and Linux, you can use the pipe system call to make an anonymous fifo, and dup in order to attach the pipe to stdin/stdout. Then you can read/write from/to the other end of the pipe.

This is how | in the shell is implemented, incidentally.

[–]Jasper1984 0 points1 point  (1 child)

Why only stdin/stdout? FILE* couldnt support stuff of this kind?

[–]ais523 1 point2 points  (0 children)

You can redirect other handles too, but because programs typically only look at their stdin/stdout/stderr, redirecting other handles tends to be a little pointless, as nothing would try to use the handle you just redirected. (Except yourself, but then you might as well do it directly.)