{-# 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
值。
答案 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'