Question

(Clojure newbie)

On my linux machine, slurping /proc/cpuinfo raises an error:

user=> (slurp "/proc/cpuinfo")
java.io.IOException: Invalid argument (NO_SOURCE_FILE:0)

Anybody knows why that is? (is the /proc filesystem some kind of second-class citizen in Java?)

Edit: the following code, adapted from nakkaya.com, works flawlessly:

(with-open [rdr (java.io.BufferedReader. 
             (java.io.FileReader. "/proc/cpuinfo"))]
   (let [seq (line-seq rdr)]
   (apply print seq)))

I wonder why this difference ?

Was it helpful?

Solution

I've had a similar problem with files in /proc. The solution is simple though:

(slurp (java.io.FileReader. "/proc/cpuinfo"))

OTHER TIPS

the problem is that java cannot open a DataInputStream on /proc so the slurp function isnt going to help you here, sorry :(

/proc/cpuinfo is a little strange because it has a file size of zero and produces bytes when read. this upsets the smarter java file handling classes.

ls -l /proc/cpuinfo
-r--r--r-- 1 root root 0 2012-01-20 00:10 /proc/cpuinfo

see this thread for more http://www.velocityreviews.com/forums/t131093-java-cannot-access-proc-filesystem-on-linux.html

you are going to have to open it with a FileReader. I'll add an example in a bit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top