如何使用 Haskell 海龟捕获进程的 stdout 和 stderr 输出?
How can I capture stdout and stderr output from a process with 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 的标准输出?
基本上,我想 运行 该过程并从 IO
操作中获得 [Line]
值而不是 ()
值。
这可以通过 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'
{-# LANGUAGE OverloadedStrings #-}
import Turtle
runSh :: Text -> IO ()
runSh x = view $ inshell x empty
main :: IO ()
main = do
runSh "echo 'abcxyz'"
我有上面的程序输出:
Line "abcxyz"
有没有一种方法可以捕获此文本而不输出到 shell 的标准输出?
基本上,我想 运行 该过程并从 IO
操作中获得 [Line]
值而不是 ()
值。
这可以通过 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'