> {:ok, ""} ...">

Elixir File.read returns empty data when accessing / proc / cpuinfo

When starting any thing, for example

File.read "/proc/cpuinfo" >> {:ok, ""} 

The same goes for the equivalent erlang function. Is there any reason for this template?

+5
source share
2 answers

Like @ José, the mentioned proc fs is special because the contents of the file are generated on the fly. If you look at the file sizes in / proc, you will see that they are 0 size.

I believe, therefore, the read function does not return anything, the file is empty!

The workaround is to force read the number of bytes anyway, in Erlang you can do:

 {ok, FD} = file:open("/proc/cpuinfo", [read]). file:read(FD, 1024). 

To read all contents, continue to read a fixed number of bytes until EOF returns with read .

+8
source

Entries in proc live under a special file system called procfs, and I believe Erlang does not support reading from it. Additional information: https://unix.stackexchange.com/questions/121702/what-happens-when-i-run-the-command-cat-proc-cpuinfo

+4
source

All Articles