Works for me if I use STDIN or STDERR instead of STDOUT. Those handles are still connected to the terminal the parent script is started from1, while STDOUT (in the child) is connected to the pipe (for which the used TIOCGWINSZ ioctl call is invalid).

___

1 unless you've reopened them to somewhere else in the Perl code, or redirected them to/from a file in the calling shell, of course...

Update:

_____ rcmd.pl _____

#!/usr/bin/perl use Term::Size; my ($col, $row) = Term::Size::chars *STDIN{IO}; print "$col x $row\n";

_____ 699419.pl _____

#!/usr/bin/perl my $rcmd = "./rcmd.pl"; if (open my $cmdh, "$rcmd |") { print <$cmdh>; }

_____

$ ./699419.pl 120 x 50 $ ./699419.pl </dev/null # doesn't work x

In reply to Re: "Exporting" Terminal Size to Piped Command? by almut
in thread "Exporting" Terminal Size to Piped Command? by PetaMem

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.