IPC::Run is portable and flexible. I think it should do what you want:
use IPC::Run qw/run/; use IO::Tee; my $tee = IO::Tee->new(">output.log", \*STDOUT); # called output.log b +ecause it's both stderr and stdout my $printer = sub { print $tee @_ }; # kludge because IO::Tee doesn't +implement the FILENO method my $in = ""; # this data is sent into the command run [qw/cleartool describe lbtype:MYLABEL/], \$in, $printer, $printer;
I'm not 100% sure this will work on windows since I can't test, but it should be OK.

IPC::Run will call the anonymous sub in $printer every time there's output on STDOUT or STDERR. That's why it's passed twice. This sub just delegates to tee, which will write the output on STDOUT and the file, like you did before.

Ideally it would look like

run [qw/cleartool describe lbtype:MYLABEL/], \$in, $tee, $tee;
But I think IPC::Run's parameter processing does not recognize $tee as a file handle, since fileno($tee) breaks.

You can also ask IPC::Run to dup STDERR to STDOUT, by doing something like this (untested):

run [qw/cleartool describe lbtype:MYLABEL/], ">&", $printer;
Which is more concise, but doesn't show how flexible IPC::Run is ;-)
-nuffin
zz zZ Z Z #!perl

In reply to Re: How do I redirect outut from system () to a file and also to screen by nothingmuch
in thread How do I redirect outut from system () to a file and also to screen by gim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.