[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] I/O oddities revisited



With apologies, I'm back again with my unreproducible 'bug'. The last time
I produced a test case, it had the bad taste to suddenly vanish as soon as
I sent it to someone else to test, before reappearing in a different form
sometime later.

My impression is that redirecting and then reopening STDOUT causes MacPerl
to get confused about where it keeps its filehandles, resulting in lost
output. Either there's a bug in MacPerl, or I've gravely misunderstood how
redirection and restoration is supposed to work. Either way, I'd be
grateful if someone can tell me how to work around the problem.

The following sample script shows the effect, at least on my system:

open(SAVEOUT,">&STDOUT");
open(STDOUT,">JunkFile.txt") ||
	die "can't open 'JunkFile.txt' for output: $!";
print "Hello world to STDOUT!\n";
print STDERR "Hello world to STDERR!\n";
close(STDOUT);
open(STDOUT,">&SAVEOUT");

If you run it repeatedly (without restarting MacPerl), you should notice
that on certain runs, nothing gets written to the console. Instead, both
output statements go to the file. On my system, this typically happens
every third run of the script. Taking out the "close()" statement seems to
cure the problem, but I'm uncertain how durable or complete a solution this
is (will re-opening a stream reliably cause previous output written to that
stream to be flushed, or do I risk losing stuff?).

I think this is a special case of a more general problem. The reason I'm so
obsessed by this is because the macro-processor I use to maintain my
Website(s) does a lot of redirection and restoration, and under MacPerls
later than 5.1.3r2 I'm dropping output and - with 5.1.9r4 - apparently
input as well.

In passing, public thanks to Mark Manning who was kind enough to test a
previous test script for me, and entirely failed to reproduce the effect I
reported. This, I think, was because I didn't tell you to run the script
repeatedly; the effect only seems to show up when one of the standard
streams is closed and then restored from a saved stream at least once.

The behaviour described occurs on the application versions of MacPerl
5.1.8r4 and 5.1.9r4 (but not under 5.1.3r2) under System 7.5.5 (PowerMac
8600/180) and MacOS 8.1 (PowerMac 7600/120).

Thanks for all help and suggestions

					A

--
angus@pobox.com                                   http://pobox.com/~angus/

    "Sick and twisted would be the first two words that come to mind," he
     said. "But at the same time, it's kind of neat." [Richard Grenier]



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch