2017-10-14 2 views
0
{-# LANGUAGE OverloadedStrings #-} 

import Turtle 

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

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

J'ai le programme ci-dessus qui, lorsqu'il exécute des sorties:Comment puis-je capturer la sortie stdout et stderr d'un processus avec une tortue Haskell?

Line "abcxyz" 

Est-il possible que je peux saisir cette sortie sans être sortie à la sortie standard du shell? Donc essentiellement je voudrais exécuter le processus et obtenir une valeur [Line] plutôt qu'une valeur () de l'action IO.

Répondre

1

Ceci est possible avec 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'