3 ms·
Writing to STDIN and reading from STDOUT (2011)
- peter_d_sherman 3y agoAny astute student of the Unix lineage -- will notice something interesting here... That is, programs usually READ from STDIN and WRITE to STDOUT... They do not usually WRITE to STDIN nor do they usually READ from STDOUT... That is, in the above article, reading and writing to the standard UNIX streams -- is reversed. Perhaps this is because the questioner did not, at the time, completely understand standard UNIX conventions... But maybe, under some circumstances -- it might be desirable to write to STDIN and read from STDOUT... Consider the following Unix command line: $ command-line-program-1 | command-line-program-2 OK, so now let's suppose that command-line-program-2 -- would like to report back to command-line-program-1 from time to time. Messages that command-line-program-1 is responsible for capturing/logging (by whatever method). These messages could be hints, warnings, statuses, and could include large chunks of text. Yes, it's quite possible that any number of other Unix mechnisms could be used for this, i.e., shared memory, shared files, named pipes, or other IPC mechanisms. But let's suppose that command-line-program-1 and command-line-program-2 don't set up anything like that beforehand -- that we just want a way to simply and easily send informational/log messages -- back through the command-line chain of programs to the first command-line program. If those were the circumstances that were desired, for whatever reason, then under those circumstances, wouldn't it make sense for each program to write to STDIN (effectively communicating with the earlier/higher-level program on the chain) and read from STDOUT (gather information/messages/feedback from the later program in the chain)... So, that is why it could/might be necessary under some circumstances, to be able to write to STDIN (and conversely) read from STDOUT... Related: The concept of "Railway Oriented Programming" in functional languages: https://fsharpforfunandprofit.com/rop/ https://fsharpforfunandprofit.com/rop/ Standard streams https://en.wikipedia.org/wiki/Standard_streams https://en.wikipedia.org/wiki/Standard_streams