Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main (module Main) where
  2.  
  3. import System.Process
  4. import System.IO
  5.  
  6. main :: IO ()
  7.  
  8.  
  9. main =  do
  10.     --putStr "Calling python.....\n"
  11.     --system "python3 script.py" >>= \exitCode -> print exitCode   --we can send commands directly to the shell if we want to
  12.     --putStr "Back in Haskell!\n"
  13.  
  14.  
  15.     (Just hin2, Just hout2, _, _) <- createProcess (proc "python3" ["-W ignore","script.py"]){ std_in = CreatePipe, std_out = CreatePipe }
  16.     putStrLn "How many clusters?"
  17.  
  18.     --hSetBuffering hin NoBuffering
  19.     clusters <- getLine
  20.     putStrLn "Sorting Questions......"
  21.     hPutStrLn hin2 clusters --Pass clusters into the std_in pipe
  22.     hFlush hin2  --important to flush, input to pipe isn't read until its flushed
  23.     lineOut <- hGetLine hout2 --read line of subprocess output from std_out pipe
  24.     dataOut <- hGetContents hout2 --read subprocess output from the std_out pipe
  25.     putStrLn dataOut
  26.     putStrLn "Back in Haskell!"
  27.     putStrLn "First line was "
  28.     putStrLn lineOut
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement