Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A pipe only conveys stdout. You could redirect 4>&1 1>/dev/null, but you'd have to rewrite all tools to generate both stdout and stdjson anyway.


> You could redirect 4>&1 1>/dev/null

For anyone confused by this, 1 is the output to stdout, and 4 is being redirected to where 1 goes, which is stdout. Unrelated to that, 1 (what’s actually being output to stout by the application) is being redirected to /dev/null.

The order of operations matters. If 1 was redirected to /dev/null first, then 4 would also end up in /dev/null. As it stands now, that doesn’t happen.


So you are supposed to read it from right to left? "First take 1 and throw it away. Next put 4 in 1." Is that how it works?


No, it's from left to right. It's basically just syntax for a series of dup2() calls.

"4>&1 1>/dev/null" means:

streams[4] = streams[1]; streams[1] = open("/dev/null");


Not quite. Left to right: copy the descriptor 1 onto descriptor 4, change descriptor 1 to result of open("/dev/null").

The >& is for copying the descriptor not for aliasing ("hardlinking") it.

The descriptor is the "fd" argument, e.g.:

write(int fd, const void *buf, size_t count)


No, it’s like assigning variables. The second part overwrites the value of 1, but the first part is still using the old value.


Good one. I did look it up before I posted, too. I’m never 100% sure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: