Skip to content

Instantly share code, notes, and snippets.

@objectx
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save objectx/9153015 to your computer and use it in GitHub Desktop.

Select an option

Save objectx/9153015 to your computer and use it in GitHub Desktop.
Invoke bash and send commands
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
@objectx
Copy link
Author

objectx commented Feb 22, 2014

Fixed in SHA: 623660b1d596c0df6b151e732d9481c58948a4ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment