When I took over maintenance of IO::CaptureOutput, I wound up fixing a
bug involving wperl.exe on windows.  It has something to do with
trying to save the original handles because they don't exist for the
GUI.  You can grep the source for "wperl" to see what changes.

Alternatively, you might just want to use IO::CaptureOutput directly
instead of writing your own.

David


On Wed, Oct 8, 2008 at 4:40 PM, Mark Tilford <[EMAIL PROTECTED]> wrote:
> My program uses the "capture_output" function (shown below) to capture
> all text printed to STDOUT.
> The program runs fine when I run it from the command prompt, or when I
> compile it with PAR as a term app, but when I compile it as a GUI app,
> it seems to freeze somewhere it the call to capture_output.  Any idea
> how to fix it?
>
>
>
> # capture_output by tmoertel http://www.perlmonks.org/?node_id=398709
> sub capture_output {
>
>    my $target_fh = shift;
>    my $temp_fh = tempfile();
>    my $temp_fd = fileno $temp_fh;
>
>    local *SAVED;
>    local *TARGET = $target_fh;
>    open SAVED, ">&TARGET" or die "can't remember target";
>    open TARGET, ">&=$temp_fd" or die "can\'t redirect target";
>    my $saved_fh = *SAVED;
>
>    return sub {
>        seek $temp_fh, 0, 0 or die "can't seek"; # rewind
>        my $captured_output = do {local $/; <$temp_fh> };
>        close $temp_fh or die "can't close temp file handle";
>        local (*SAVED, *TARGET) = ($saved_fh, $target_fh);
>        open TARGET, ">&SAVED" or die "can't restore target";
>        close SAVED or die "can't close SAVED";
>        return $captured_output;
>    }
> }
>

Reply via email to