Herbert Valerio Riedel <h...@gnu.org> wrote:
Try to keep hin/hout "alive" a bit longer, and mpg123 should survive
longer. Also you should most probably consume the output comming from
'mpg123 -R' via 'hout', as otherwise it the buffer might build up and
mpg123 might block.
[1]:
http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/System-IO.html#t:Handle
Shame of me, I've opened that link several times without noticing that
paragraph.
You're quite right. After understanding the details, I think there can be
many solutions.
But at present, I'm satisfied with this quick fix:
import System.Exit
import System.IO
import System.Process
import Control.Concurrent
mpgLoop = do
let sh = "mpg123 -R"
(Just hin, Just hout, _, hdl) <- createProcess (shell sh){ std_in =
CreatePipe, std_out = CreatePipe }
hPutStrLn hin "SILENCE" -- mildly prevent buffer blocking
hPutStrLn hin "LOAD /home/rnons/Music/test.mp3"
hFlush hin
waitForProcess hdl >>= exitWith
hPutStrLn hin "STOP" -- keep hin "alive" a bit longer
hGetContents hout
hFlush hin
return ()
main = do
forkIO mpgLoop
getChar
Thank you very much!
rnons
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe