Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main (module Main) where
- import System.Process
- import System.IO
- main :: IO ()
- main = do
- --putStr "Calling python.....\n"
- --system "python3 script.py" >>= \exitCode -> print exitCode --we can send commands directly to the shell if we want to
- --putStr "Back in Haskell!\n"
- (Just hin2, Just hout2, _, _) <- createProcess (proc "python3" ["-W ignore","script.py"]){ std_in = CreatePipe, std_out = CreatePipe }
- putStrLn "How many clusters?"
- --hSetBuffering hin NoBuffering
- clusters <- getLine
- putStrLn "Sorting Questions......"
- hPutStrLn hin2 clusters --Pass clusters into the std_in pipe
- hFlush hin2 --important to flush, input to pipe isn't read until its flushed
- lineOut <- hGetLine hout2 --read line of subprocess output from std_out pipe
- dataOut <- hGetContents hout2 --read subprocess output from the std_out pipe
- putStrLn dataOut
- putStrLn "Back in Haskell!"
- putStrLn "First line was "
- putStrLn lineOut
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement