When running any thing like
File.read "/proc/cpuinfo"
>> {:ok, ""}
Same for equivalent erlang function. Is there some reason for this pattern?
Like @José mentioned the proc fs is special since the file contents are generated on the fly. If you look at the file sizes in /proc you'll see that they have size 0
.
I believe this is why the read
function fails to return anything, the file is empty!
The workaround is to force-read a number of bytes anyway, in Erlang you can do:
{ok, FD} = file:open("/proc/cpuinfo", [read]).
file:read(FD, 1024).
To read all the content keep reading fixed number of bytes until EOF is returned by read
.
Entries in proc live under a special filesystem called procfs and I believe Erlang does not support reading from it. More info: https://unix.stackexchange.com/questions/121702/what-happens-when-i-run-the-command-cat-proc-cpuinfo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With