3 ms·
If your program is expected to operate in a pipeline, as most UNIX programs are, shouldn't you always check for printf returning an error? For example: yo
by apw 13y ago
If your program is expected to operate in a pipeline, as most UNIX programs are, shouldn't you always check for printf returning an error? For example:
yourprogram | head -100
- dilap 13y agoI'm not sure, actually, what's the proper way to do it? For fun, I wrote three programs that just print 1 2 3 ... to stdout forever, in python, go, and plain c. None do any error checking. Here's the results: $ py printcount.py | head -10 1 2 3 4 5 6 7 8 9 10 Traceback (most recent call last): File "printcount.py", line 3, in <module> print i IOError: [Errno 32] Broken pipe $ go run printcount.go | head -10 1 2 3 4 5 6 7 8 9 10 signal: broken pipe $ ./printcount | head -10 1 2 3 4 5 6 7 8 9 10 $ pgrep printcount $ Interestingly enough, only plain old C actually did what I wanted here. In Go and Python, we'd have to do a little work to not print the annoying error. But I don't think we want to check return codes from print in any of the languages.