Capture stdout from a command on Windows

Hi, I'm trying to capture the output (stdout) of a command on Windows. This is what I have so far: import System.Process (runProcess, waitForProcess) import System.IO (hGetContents) executeCapturingStdout :: String -> String -> IO [String] executeCapturingStdout cmd workingDir = do let stdoutHandle = -- TODO: What do I put here? processHandle <- runProcess cmd [] (Just workingDir) Nothing Nothing stdoutHandle Nothing exitCode <- waitForProcess processHandle content <- hGetContents stdoutHandle return lines content I have tried searching on google and I haven't been able to find an answer yet. Thanks, Dave

Hi, you might use runInteractiveProcess which returns the process handle and three handles hIn, hOut and hErr for communication with the process. Besh wishes, Maciej David Frey wrote:
Hi,
I'm trying to capture the output (stdout) of a command on Windows.
This is what I have so far:
import System.Process (runProcess, waitForProcess) import System.IO (hGetContents)
executeCapturingStdout :: String -> String -> IO [String] executeCapturingStdout cmd workingDir = do let stdoutHandle = -- TODO: What do I put here? processHandle <- runProcess cmd [] (Just workingDir) Nothing Nothing stdoutHandle Nothing exitCode <- waitForProcess processHandle content <- hGetContents stdoutHandle return lines content
I have tried searching on google and I haven't been able to find an answer yet.
Thanks, Dave _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Under Unix I use readProcess or readProcessWithExitCode from System.Process to get the output without fiddling with handles. HTH Christian Am 15.09.2010 20:08, schrieb David Frey:
Hi,
I'm trying to capture the output (stdout) of a command on Windows.
This is what I have so far:
import System.Process (runProcess, waitForProcess) import System.IO (hGetContents)
executeCapturingStdout :: String -> String -> IO [String] executeCapturingStdout cmd workingDir = do let stdoutHandle = -- TODO: What do I put here? processHandle <- runProcess cmd [] (Just workingDir) Nothing Nothing stdoutHandle Nothing exitCode <- waitForProcess processHandle content <- hGetContents stdoutHandle return lines content
I have tried searching on google and I haven't been able to find an answer yet.
Thanks, Dave
participants (3)
-
Christian Maeder
-
David Frey
-
Maciej Podgurski