haskell-03-process.hs 963 Bytes
Newer Older
epsi sayidina's avatar
epsi sayidina committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import System.Process
import System.IO

import Data.Time.LocalTime
import Data.Time.Format

import Control.Concurrent
import Control.Monad

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- wrap Funktion

wFormatTime :: FormatTime t => t -> String
wFormatTime myUtcTime = formatTime 
epsi sayidina's avatar
epsi sayidina committed
15 16
    Data.Time.Format.defaultTimeLocale myTimeFormat myUtcTime
  where myTimeFormat = "%a %b %d %H:%M:%S"
epsi sayidina's avatar
epsi sayidina committed
17 18

wSleep :: Int -> IO ()
epsi sayidina's avatar
epsi sayidina committed
19
wSleep mySecond = threadDelay (1000000 * mySecond)
epsi sayidina's avatar
epsi sayidina committed
20

epsi sayidina's avatar
epsi sayidina committed
21
generatedOutput pipein = do
epsi sayidina's avatar
epsi sayidina committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
     now <- getZonedTime
     let nowFmt = wFormatTime now

     hPutStrLn pipein nowFmt
     hFlush pipein

     wSleep 1

cmdout = "less" -- or dzen2

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main

main = do
    (Just pipein, _, _, ph)  <- 
        createProcess (System.Process.proc cmdout []) 
        { std_in = CreatePipe }
    
epsi sayidina's avatar
epsi sayidina committed
40
    forever $ generatedOutput pipein
epsi sayidina's avatar
epsi sayidina committed
41 42
    hClose pipein
    
epsi sayidina's avatar
epsi sayidina committed
43
    putStr ""