[GHC] #3231: Permission denied error with runProcess/openFile
GHC
trac at galois.com
Thu Sep 10 06:11:40 EDT 2009
#3231: Permission denied error with runProcess/openFile
---------------------------------+------------------------------------------
Reporter: NeilMitchell | Owner: simonmar
Type: bug | Status: closed
Priority: normal | Milestone: 6.12.1
Component: Runtime System | Version: 6.10.4
Severity: normal | Resolution: invalid
Keywords: | Difficulty: Unknown
Testcase: | Os: Windows
Architecture: Unknown/Multiple |
---------------------------------+------------------------------------------
Changes (by simonmar):
* status: new => closed
* resolution: => invalid
Comment:
Repeating the program, to get the markup right:
{{{
module Main where
import System
import System.IO
import System.Process
import System.Directory
import Control.Monad
import Data.List
import Control.Concurrent
tempFile = "mytempfile.txt"
run :: FilePath -> IO String
run exe = do
h <- openFile tempFile WriteMode
pid <- runProcess exe [] Nothing Nothing Nothing (Just h) Nothing
exitCode <- waitForProcess pid
hClose h
if exitCode /= ExitSuccess
then error $ exe ++ " failed"
else readFile tempFile
main = replicateM_ 10 $ run "ls"
}}}
The program does indeed fail with `openFile: permission denied`, but it's
not a problem with `runProcess`. In the `else` branch of the `if` you
have a `readFile` which opens a lazy stream to read `tempfile`, and then
the next iteration attempts to open the file for writing. It's illegal to
have the same file open for both reading and writing, hence the error.
Unfortunately neither myself nor Duncan Coutts spotted the problem
immediately, because we were looking in the wrong place. `readFile`
considered harmful, IMO!
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3231#comment:27>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list