The IOUtil structure provides support for redirecting the standard input
and output streams.
Synopsis
signature IO_UTIL
structure IOUtil : IO_UTIL
Interface
val withInputFile : string * ('a -> 'b) -> 'a -> 'b
val withInstream : TextIO.instream * ('a -> 'b) -> 'a -> 'b
val withOutputFile : string * ('a -> 'b) -> 'a -> 'b
val withOutstream : TextIO.outstream * ('a -> 'b) -> 'a -> 'b
Description
val withInputFile : string * ('a -> 'b) -> 'a -> 'b-
withInputFile (file, f) xevaluates the expressionf xwith standard input bound tofile. The file is closed and theTextIO.stdIninput stream is restored to its original binding once evaluation terminates. val withInstream : TextIO.instream * ('a -> 'b) -> 'a -> 'b-
withInstream (inS, f) xevaluates the expressionf xwith standard output redirected toinS. TheTextIO.stdIninput stream is restored to its original binding once evaluation terminates. val withOutputFile : string * ('a -> 'b) -> 'a -> 'b-
withOutputFile (file, f) xevaluates the expressionf xwith standard output redirected tofile. The file is closed and theTextIO.stdOutoutput stream is restored to its original destination once evaluation terminates. val withOutstream : TextIO.outstream * ('a -> 'b) -> 'a -> 'b-
withOutstream (outS, f) xevaluates the expressionf xwith standard output redirected tooutS. TheTextIO.stdOutoutput stream is restored to its original destination once evaluation terminates.
Example
The following expression will put its output in the file "hello.txt":
withOutputFile ("hello.txt", fn () => print "hello world\n") ()