[erlang-questions] file:read_file won't read from /proc

Mikael Pettersson mikpe@REDACTED
Thu Mar 4 18:52:23 CET 2010


Jachym Holecek writes:
 > Hello,
 > 
 > # Martin DeMello 2010-03-04:
 > > 4> {ok, B} = file:read_file("/proc/cpuinfo").
 > > {ok,<<>>}
 > > 
 > > Why is B empty?
 > 
 > The read_file/1 thing check file size and then attempts to read exactly
 > that many bytes. The size of /proc/cpuinfo is zero[*], thus read_file/1
 > correctly reads zero bytes and represents the result with empty binary.
 > 
 > Gotta love UN*X for its sense of consistency, right? ;-)

/proc files behave more like pipes than regular files,
because their contents are not stored but generated on the fly.

You really have to 'cat' them and not rely on stat to tell
you their sizes in advance.


More information about the erlang-questions mailing list