[Haskell-cafe] using an external application

Petr Hoffmann spy.hunter at email.cz
Fri Nov 2 04:17:23 EDT 2007


I'm solving the following problem - I need to use an external
application - give it the input data and receive its output.
However, when multiple calls are made, the results are not
as expected. The simplified version of the problem is given

import System.Cmd
main = do
          System.Cmd.system "echo hello >output.txt" -- use the external  
application to create an output file
          o1 <- readFile "output.txt"
          System.Cmd.system "echo bye >output.txt" -- the second call to  
the external application
          o2 <- readFile "output.txt"
          putStr o1 -- "hello" expected, but "bye" printed
          return 0

Can you please give me some hint to solve this problem?
I'm a beginning haskell developer and I'm still a bit confused
by the IO monad.

Thank you in advance.


More information about the Haskell-Cafe mailing list