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) x
evaluates the expressionf x
with standard input bound tofile
. The file is closed and theTextIO.stdIn
input stream is restored to its original binding once evaluation terminates. val withInstream : TextIO.instream * ('a -> 'b) -> 'a -> 'b
-
withInstream (inS, f) x
evaluates the expressionf x
with standard output redirected toinS
. TheTextIO.stdIn
input stream is restored to its original binding once evaluation terminates. val withOutputFile : string * ('a -> 'b) -> 'a -> 'b
-
withOutputFile (file, f) x
evaluates the expressionf x
with standard output redirected tofile
. The file is closed and theTextIO.stdOut
output stream is restored to its original destination once evaluation terminates. val withOutstream : TextIO.outstream * ('a -> 'b) -> 'a -> 'b
-
withOutstream (outS, f) x
evaluates the expressionf x
with standard output redirected tooutS
. TheTextIO.stdOut
output 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") ()