with-output-to-file

Name

with-output-to-file -- Redirect output to a file

Type: function

Synopsis

with-output-to-file( string thunk, );

Arguments

string

An instance of <string> representing a file name

thunk

A procedure of no arguments

Description

This procedure creates a new output port referring to the system file string, as does the procedure open-output-file. It then calls the given thunk in a dynamic context such that the current output port is the new output port. If the procedure returns, then the port will be closed as with close-output-port. If the procedure does not return, the port will not be closed until and unless it can be shown (as by the reachability analysis done by the garbage collector) that the port cannot be used for any output operations.