如何从Haskell龟的进程中捕获stdout和stderr输出?

时间:2017-10-14 13:49:04

标签: haskell haskell-turtle

{-# LANGUAGE OverloadedStrings #-}

import Turtle

runSh :: Text -> IO ()
runSh x = view $ inshell x empty

main :: IO ()
main = do
  runSh "echo 'abcxyz'"

我有上面的程序,当执行输出时:

Line "abcxyz"

有没有办法可以捕获此输出而不输出到shell的标准输出?

基本上我想运行该过程并获得[Line]值,而不是()操作中的IO值。

1 个答案:

答案 0 :(得分:1)

这可以使用shellStrictWithErr

{-# LANGUAGE OverloadedStrings #-}

import Turtle (empty, shellStrictWithErr, ExitCode)
import Data.Text (Text)

runSh :: Text -> IO (ExitCode, Text, Text)
runSh x' = shellStrictWithErr x' empty

main :: IO ()
main = do
  (e, v, v') <- runSh "ls"
  print e
  print v
  print v'