Last active
August 29, 2015 13:56
-
-
Save objectx/9153015 to your computer and use it in GitHub Desktop.
Invoke bash and send commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main (main) where | |
| import Control.Concurrent (forkIO) | |
| import Control.Monad (forM_) | |
| import System.IO (hFlush, hGetContents, hPutStr) | |
| import System.Process (createProcess, proc, StdStream(..), CreateProcess(..)) | |
| testScript :: [String] | |
| testScript = [ "ls -lR" | |
| , "sleep 5" | |
| , "ps awx" | |
| , "sleep 5" | |
| , "echo THE-END"] | |
| main :: IO () | |
| main = do | |
| let p = (proc "bash" ["-evx"]){ std_in = CreatePipe, std_out = CreatePipe, std_err = Inherit } | |
| (Just hIn, Just hOut, _, _) <-createProcess p | |
| forkIO $ do | |
| forM_ testScript $ \cmd -> do | |
| hPutStr hIn cmd | |
| hPutStr hIn "\n" | |
| hFlush hIn | |
| putStr =<< hGetContents hOut |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed in SHA: 623660b1d596c0df6b151e732d9481c58948a4ad