Управляем потоками в Linux: от stdin до stderr
Привет, Хабр! Сегодня рассмотрим работу с потоками в Linux: stdin, stdout, stderr и, конечно, все эти оператора редиректа.
Управляем потоками в Linux: от stdin до stderr
Привет, Хабр! Сегодня рассмотрим работу с потоками в Linux: stdin, stdout, stderr и, конечно, все эти оператора редиректа.
#Unix & #Linux #CLI Buffering Tips
I recently posted about some pragmatic differences between #stdbuf from #GNU #coreutils and the #unbuffered command from the #Expect tool examples. Both were installed and tested using #Homebrew on #macOS. The TL;DR is that `unbuffered` is easier and works on #stdin, while `stdbuf` gives you more options for each separate I/O stream.
Wrote this #lisp hello world #gui #cloud app last few minutes, just smart enough to draw and exit on right click. Just uses #stdin #stdout output same as the #bash and #C implementations (setq x "Fo 0 999 3\nF 0 255\nL$ 0 0 800\"Hello world\"\nZ \n")
(while (setq p (asc (fgets stdin))) (cond ((== p 100) (write 1 x (strlen x))) ((== p 51) (exit 0)))) This code is out on bitbucket timcdoc antibrowser lisp hello (sub C or bash for lisp to see others)
Graphing part is working, just hard coded fns for now, but it's a start! #lisp #antibrowser #cloud #app #thinclient #NoFont #stdin #stdout [[oh code, my lisp, ancient variant, out on https://bitbucket.org/timcdoc/antibrowser/src/master/lisp/sh73/
If nothing happens, maybe it waits for stdin?
`input` in #python read from #stdin. It's pretty straight forward.
But this is how *most* tools work in Linux. Often times you can give them data on stdin instead of in a file. In Python you might do it like
import sys
if len(sys.argv) > 1:
with open(sys.argv[0]) as f:
data = f.read()
else:
data = sys.stdin.read()
You've gotta .read() from stdin, since `input` just looks for the first newline. Anyway. Piping is a very fundamental part of Linux command line.
Now remember - so far all of this is just to get two lists - my TableOfContents and all of the WikiWords that exist in my file.
If you use #Linux or #Unix for any period of time (or #GnuLinux - where my pedants at?), you will probably have come across `sort`.
Now we get to talk about streams and files!
Everything in Linux is a file. Which is shockingly powerful. Input from the keyboard? A file you can read from. Output to the screen? A file you can write to. #stdin and #stdout are their names
Wildes #Ausprobieren.
#Was ist #eingeschlossen?
#Was ist #ausgeschlossen?
#stdin #stdout #stderr
#Input / #Output / #Error (Output)
Ein #Fall, in dem ich (noch) nicht #imstande bin, #Anweisungen einzusehen, ich also nur durch #ausprobieren #herausfinden kann, was ein- und was #ausgeschlossen ist. Keine #Möglichkeit also, (un)vollständigkeit festzustellen
#Einsehen; #Vollständigkeit; #Unvollständigkeit; #Feststellung