How to Write into multiple files?

10

2

Note: this is fixed in version 9.


I want to put expressions into multiple files simultaneously, with the following code:

tex1 = OpenWrite["test1.txt"];
tex2 = OpenWrite["test2.txt"];

Write[{tex1, tex2}, "anything"]

Close[tex1];
Close[tex2];

Why is test2.txt empty? Why does it work correctly with WriteString instead of Write? Now of course I can always Map the Write statements over streams, or just go with WriteString, but since it would be convenient to use a list as Write's first argument I did post this issue. Is it a bug?

István Zachar

Posted 2012-01-31T14:01:56.340

Reputation: 44 135

@ArnoudBuzing, what do you think of this? – rcollyer – 2012-01-31T15:42:01.147

2It seems like a possible bug. I will report it. – Arnoud Buzing – 2012-02-01T00:37:07.360

@ArnoudBuzing István has indicated that this bug has been unfixed for at least 5 years: http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/bd9b6dfd356fa886/dfe3e85496a3d2b4?hl=en&lnk=gst&q=Istv%C3%A1n+Zachar#dfe3e85496a3d2b4

– Mike Honeychurch – 2012-02-01T01:30:01.600

@ArnoudBuzing: Thanks for reporting it. This raises another meta question in me...

– István Zachar – 2012-02-01T09:33:02.610

Answers

4

This is a bug and fixed in the development version. Thanks for pointing it out.

user21

Posted 2012-01-31T14:01:56.340

Reputation:

7

According to the docs, both Write and WriteString should accept an "output channel," which is just a list of streams. On my system (v.8 on MacOS), Write behaves the same way as on your system when outputting anything, but WriteString behaves as expected.

Similarly, this

Write[{tex1, tex2}, 3, 4];

also misbehaves in the same manner. So, the issue isn't limited to string output.

rcollyer

Posted 2012-01-31T14:01:56.340

Reputation: 32 561