28 ms·
It'd be useful if there was a standardized way for applications to expose additional streams that worked exactly like stdin/stdout/stderr but with custom names.
by Crinus 7y ago
It'd be useful if there was a standardized way for applications to expose additional streams that worked exactly like stdin/stdout/stderr but with custom names.
At a first glance, named pipes (both the Unix and the Windows approach) sound like that, but they are global names - i can't have an application exposing a "commands" output stream that from the shell is piped to awk which is then piped to a "monitor" input stream of another application - and then have arbitrary number of instances of those.
You can ducktape a solution using randomly created unique global names and some shell script code, but what i think would be nice is something like:
/* app1 */
FILE* commands = stream("commands", "w"); /* write-only stream */
/* app2 */
FILE* terminal = stream("terminal", "r"); /* read-only stream */
that could be used via something like (:foo would be used wherever a file descriptor could be used to specify stream foo)
# redirect commands stream from app1 to terminal stream of app2
app1 :commands>&:terminal app2
# redirect commands stream from app1 to stdout
# (stdin of the right side which is empty, hence stdout)
app1 :commands>&0
# pipe commands to awk's stdin then grep then app2's terminal stream
# regular app1 stdout is not affected and written wherever stdout is
app1 :commands| awk blah | grep bleh 1>&:terminal | app2
the shell syntax would also need to be extended a bit to allow for parallel pipelines (e.g. app1 could also export a "comments" stream that could be piped to a separate file or to a projector application).
- DSpinellis 7y agoSee the Directed Graph Shell (dgsh), which does allow multiple streams across commands. https://www.spinellis.gr/sw/dgsh/ https://www.spinellis.gr/sw/dgsh/
- Crinus 7y agoNeat but i think this would be more useful if it was a standalone utility that did the launching itself instead of replacing your existing shell.