Re: With[..] not working with $Output
- To: mathgroup at smc.vnet.net
- Subject: [mg106343] Re: With[..] not working with $Output
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Fri, 8 Jan 2010 06:37:51 -0500 (EST)
- References: <hi6t64$a6b$1@smc.vnet.net>
Hi, > does anybody have an idea why redirecting output using a With does not > > work (version 7 Vista)? > > Consider redefining the list $Output: > > > > fun1 := ( > > old = $Output; > > $Output = {OpenWrite["c:/tmp.txt"]}; > > Print["gaga"]; > > Close["c:/tmp.txt"]; > > $Output = old;) > > fun1; > > > > fun2 := With[{$Output = {OpenWrite["c:/tmp.txt"]}}, > > Print["123"]; > > Close["c:/tmp.txt"]; > > ]; > > fun2; > > > > Both functions f1 and f2 redefine $Output. fun1 works as expected, it > > puts the output from Print in a file. fun2 on the contrary puts nothing > > in the file, but writes the output to the screen. Therefore, "With"does > > not work in this case. Actually f2 also works as expected, at least if you know what With is doing. You want Block not With, With is just doing the wrong thing for what you want, and also Module will not work. It is a good example for the difference of the three... hth, albert