my $fooFile = "foo.out"; unlink $fooFile; #close STDOUT; # with this it works open STDOUT, ">>:encoding(cp37)", $fooFile or die "Cannot redirect STDOUT\n"; select(STDOUT); $| = 1; print "yadda yadda\n"; close STDOUT;Is this working as expected or should it work without the close() in there?
Maybe I don't understand what you are trying to do ... but why not use a different file handle? You might consider redirecting STDOUT by using select:
open (FOOFILE, ">>:encoding(cp37)") or die "Some error message: $!\n"; select FOOFILE; print "yadda yadda\n"; close(FOOFILE); select STDOUT;
system "ls";
in there in the original case the output from ls will go to the file (albeit not encoded) but using select it won't. I think they want this to work for all output going to the user's console device.
Though if you try to re-open COf course this isn't talking about encodings, but I think it might be the same problem. Unless a PerlIO guru pops up here, I'd suggest asking p5p.or C as an "in memory" file, you have to close it first: close STDOUT; open STDOUT, '>', \$variable or die "Can't open STDOUT: $!";
PS. If you just want a minimal demonstration script, you can delete most of your code:
# close STDOUT; # with this it works open STDOUT, ">:encoding(cp37)", "foo.out" or die "Cannot redirect STDOUT\n"; print "yadda yadda\n";
perlmonks.org content © perlmonks.org and BillSeurer, DungeonKeeper, ptum, robin
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03