Reputation: 1271
How do I feed a string to shell command and get the output it produces in Haskell?
For example, given this:
> myHaskellProg
"blah"
> myHaskellProg | wc
4
I want
> myHaskellProg
to print 4
by calling wc
and printing out the result
I was able to call shell commands using process
's callCommand
but how do I pipe a string to it and get back the result or stderr?
Upvotes: 2
Views: 516
Reputation: 64740
You are looking for System.Process
and you can use the shell
function to create a description of a process then use readCreateProcess
to run the shell command, provide stdin and read stdout.
import System.Process
main :: IO ()
main =
do result <- readCreateProcess (shell "ls") myHaskellString
putStrLn result
myHaskellString :: String
myHaskellString = "string"
Upvotes: 5