Stephen Edwards (edwards@CS.VT.EDU)
Mon, 6 Mar 2000 09:22:28 -0500
Message-ID: <38C3BF24.112590E@cs.vt.edu> Date: Mon, 6 Mar 2000 09:22:28 -0500 From: Stephen Edwards <edwards@CS.VT.EDU> Subject: Re: [CS3304_1381] standard out redirection
> Is there a way to redirect standard output from the console to a file with
> MIT Scheme? Thanks.
There is a function called "with-output-to-file" that works similarly
to the "with-input-from-file" predicate I described in an earlier
message. If your main program is called "my-program" and takes 0
arguments, then you can use this:
(with-output-to-file "output.txt" my-program)
If you want to simultaneously redirect both input and output, combining
with-input-from-file and with-output-to-file is a bit tricky, since they
both expect a zero-argument function object as their third argument. The
following function definition shows how to combine them correctly using a
lambda expression:
(define (with-redirected-io input-file output-file command)
(with-output-to-file
output-file
(lambda () (with-input-from-file input-file command))
)
)
This defines a more general purpose function that will allow you to
execute your program like this:
(with-redirected-io "myinput.txt" "myoutput.txt" my-program)
-- Steve
-- Stephen Edwards 641 McBryde Hall Dept. of Computer Science e-mail : edwards@cs.vt.edu U.S. mail: Virginia Tech (VPI&SU) office phone: (540)-231-5723 Blacksburg, VA 24061-0106 -------------------------------------------------------------------------------
This archive was generated by hypermail 2.0b3 on Mon Mar 06 2000 - 09:22:40 EST