Without investigating why localizing doesn't work, here's something that does the job. See open.
my $file = "file.txt"; print "before\n"; { open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: $!"; open (STDOUT, ">$file") or die; system("ls"); open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!"; } print "after\n";
In reply to Re: Localized STDIO and system()
by shmem
in thread Localized STDIO and system()
by mill1359
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |