Linux nuisance: /dev/stdin doesn't work with sockets
1
vote
2
answers
2508
views
Linux has this blitheringly annoying peculiarity that
/dev/stdin
won't work with sockets - it is hardcoded to return ENXIO. Try this:
socat TCP-OPEN:localhost:1234 EXEC:cat\ /dev/stdin,nofork
That's a perfectly reasonable command you'd expect to work, and does on basically every system, except Linux. (I'm using cat
as a general example of any tool that opens a filename as the only way for you to specify a specific fd to use.)
The linux kernel is explicitly written to forbid sensible use of /dev/stdin
in this way — see http://marc.info/?l=ast-users&m=120978595414993 .
If you only need unidirectional capability, you can buffer the data in a separate process:
socat TCP-OPEN:localhost:1234 SYSTEM:'cat | thingy /dev/stdin'
It's wasteful, and worse, is useless if thingy
is meant to be reading and writing to the same fd, because pipes are unidirectional in Linux.
What are we meant to do? /dev/stdin
simply can't be used on Linux for building pipelines with bidirectional pipes, as far as I can tell, because sockets are the only underlying mechanism on Linux that yield a bidi stream with a single fd to read and write from (unlike a pair of pipes).
Asked by Nicholas Wilson
(1088 rep)
Nov 5, 2013, 03:38 PM
Last activity: May 21, 2025, 04:27 PM
Last activity: May 21, 2025, 04:27 PM