Hi all,<br><br>It's the first time I use the runInteractiveCommand and I was probably bitten by laziness.<br><br>When I run the following program and send its output to a file using '>' redirection I get the full output of the called process. But if I run it in the console I get only half of the output. As console is slower than disk I assume the called process terminates before all data has been read from it or the main process terminates before data has been written to stdout. I thought using waitForProcess, closing called process output and flushing stdout would solve the problem but it doesn't.<br>
<br>> -- Compile with -threaded option<br>> module Main where<br>> <br>> import Control.Concurrent (forkIO)<br>> import System.Environment (getArgs)<br>> import System.FilePath (dropExtension, takeFileName)<br>
> import System.IO (Handle, hClose, hFlush, hGetContents, stdout)<br>> import System.Process (runInteractiveCommand, waitForProcess)<br>> <br>> main :: IO ()<br>> main = do<br>> (file:_) <- getArgs<br>
> (_, out, _, pid) <- runInteractiveCommand $ "dumpbin /EXPORTS " ++ file<br>> forkIO (createDefFile file out)<br>> waitForProcess pid<br>> hClose out<br>> hFlush stdout<br>> <br>> createDefFile :: String -> Handle -> IO ()<br>
> createDefFile file inp = do<br>> putStrLn $ "LIBRARY " ++ (dropExtension . takeFileName) file ++ ".dll"<br>> putStrLn "EXPORTS"<br>> text <- hGetContents inp<br>> mapM_ writeExport $ keepExports $ map words $ lines text<br>
> where<br>> keepExports :: [[String]] -> [String]<br>> keepExports = map head<br>> . filter (not . null)<br>> . takeWhile (["Summary"]/=)<br>> . drop 1<br>
> . dropWhile (["ordinal","name"]/=)<br>> writeExport ('_':xs) = putStrLn xs<br>> writeExport xs = putStrLn xs<br><br>Any idea regarding the cause of this problem?<br>
<br>
Thanks,<br>
<br>
Olivier.<br>
<br>