[Haskell-cafe] problem reading /proc/interrupts with ByteString
Leandro Lisboa Penz
lpenz at terra.com.br
Sat May 26 13:56:56 EDT 2007
Hi
I'm having some problems using ByteString.Char8.readFile to read
"/proc/interrupts". I reads nothing. I guess maybe that's because the
file is sort of special, but I could read it by opening and using
ByteString.Char8.hGetContents.
The part of interest is:
findInterrupts :: B.ByteString -> Int
findInterrupts str = findI
where
findI = read $ B.unpack $ getNums $ skipSpaces $ skip1
from1 = case B.findSubstring (B.pack "1:") str of
Nothing -> error $ "Not found in [" ++ B.unpack str ++ "]"
Just a -> a
skip1 = B.drop from1 str
skipSpaces = B.dropWhile (\c -> c == ' ')
getNums = B.takeWhile (\c -> c `elem` "1234567890")
getNumInterrupts :: IO Int
getNumInterrupts = do
h <- openFile "/proc/interrupts" ReadMode
c <- B.hGetContents h
hClose h
-- c <- B.readFile "/proc/interrupts"
-- With readFile the contents are emtpy
-- B.putStrLn c
return $ findInterrupts c
Whole code can be found at http://hpaste.org/63
Thanks in advance
Leandro Penz
More information about the Haskell-Cafe
mailing list