I am trying to spawn a process from within a Haskell program, and I would like to print its standard error stream to the screen while also writing the same stream to a file, much like what the tee
command achieves.
I can print the standard error stream:
import Data.Conduit ((.|), runConduit)
import qualified Data.Conduit.List as CL
import Data.Conduit.Process
main :: IO ()
main = do
(ClosedStream, ClosedStream, err, sph) <- streamingProcess (shell myCommand)
runConduit $ err .| CL.mapM_ print
And I can direct the stream to a file:
import System.IO (withFile, IOMode (..))
import Data.Conduit.Process
main :: IO ()
main = do
let logFile = "myCommand.log"
withFile logFile WriteMode $ \h -> do
(ClosedStream, ClosedStream, UseProvidedHandle, sph) <-
streamingProcess (shell myCommand) {std_err = UseHandle h}
How can I do both simultaneously?
print
/printC
, does there exist an analogous version ofputStrLn
? – Resistor