Capturing output from System.system
Hi All Haskeleers The function System.system (:: String -> IO ExitCode) makes the OS execute it first parameter as a command. It prints its output to standard output and standard error. How do I easily capture this output? /Mads Lindstrøm
Mads Lindstrøm wrote:
The function System.system (:: String -> IO ExitCode) makes the OS execute it first parameter as a command. It prints its output to standard output and standard error.
How do I easily capture this output?
There's Jens-U Petersen's rather old popenhs module, which you could dust off and use: http://www.haskell.org/~petersen/haskell/popenhs/ <b
Sorry Mads for multiple copies. On 16/01/07, Mads Lindstrøm <mads_lindstroem@yahoo.dk> wrote:
The function System.system (:: String -> IO ExitCode) makes the OS execute it first parameter as a command. It prints its output to standard output and standard error.
How do I easily capture this output?
Try System.Process.runInteractiveCommand: import System.Process import System.IO main = do (inH, outH, errH, _) <- runInteractiveCommand "wc -w" hPutStr inH "foo bar baz" ws <- hGetContents outH putStrLn ws -- Prints 3 -- -David House, dmhouse@gmail.com
"David House" <dmhouse@gmail.com> writes:
Sorry Mads for multiple copies.
On 16/01/07, Mads Lindstrøm <mads_lindstroem@yahoo.dk> wrote:
The function System.system (:: String -> IO ExitCode) makes the OS execute it first parameter as a command. It prints its output to standard output and standard error.
How do I easily capture this output?
Try System.Process.runInteractiveCommand:
import System.Process import System.IO
main = do (inH, outH, errH, _) <- runInteractiveCommand "wc -w" hPutStr inH "foo bar baz" ws <- hGetContents outH putStrLn ws
-- Prints 3
Beware, deadlocks ahead. See: http://www.haskell.org/pipermail/libraries/2006-December/006635.html http://www.haskell.org/pipermail/haskell-cafe/2006-December/020528.html -- Feri.
participants (4)
-
Bryan O'Sullivan -
David House -
Ferenc Wagner -
Mads Lindstrøm