Re: sys call length limitation

Discussion in 'Perl Misc' started by Tim McDaniel, Jan 22, 2014.

  1. Tim McDaniel

    Tim McDaniel Guest

    In article <6RDDu.243526$>,
    * Tong * <> wrote:
    >I just found out that there is a strict limitation on how many characters
    >one can stuff in between `` sys calls:
    >
    > $ echo "`cat HttpBody`" | wc -c
    > 238566
    >
    > $ cat HttpBody | perl -e '$s = <>; print length $s; print `echo $s`'
    > 238566
    >
    >I.e., the echo works fine in my shell, but not OK within Perl.


    To be more precise, not OK within *your* Perl. On the system I'm on
    on the moment,

    $ perl -e 'print("x" x 238565, "\n")' > HttpBody
    $ echo "`cat HttpBody`" | wc -c
    238566
    $ <HttpBody perl -e '$s = <>; print length $s, "\n"; print `echo $s`' |
    less
    238566
    xxxxxxxxxxx...

    But that's something of a quibble. On this system, using 2385651
    works in the echo...wc... command but does not work in Perl.

    (As a side note, note that "cat ... |" is usually a useless use of a
    program. Ending the perl call with "<HttpBody" would work as well or
    better. As shown above, at least in bash on this system, "<" and
    other file redirection characters work anywhere in the command line --
    I usually put them at the end, but putting them at the front, as
    above, makes them more visually evident.)

    >Any way to increase the sys call length limitation, ie the limitation
    >how many characters one can stuff in between ``?


    There may well be, but there's an old joke:
    "Doctor, doctor, it hurts when I do this!"
    "Then don't do this!"

    Don't do `...` when there may be a lot of output. Please see the
    perlopentut man page, specifically "pipe open", and don't try to pass
    long values on the command line. Mind you, translating it naively to
    a pipe open of echo doesn't work either on my system for 2385651:

    $ <HttpBody perl -e '$s = <>; print length $s, "\n"; open my $f, "-|", "echo", $s or die "$!"; print <$f>'
    2385651
    Argument list too long at -e line 1, <> line 1.

    but of course it is silly to try to put it on the command line.

    --
    Tim McDaniel,
    Tim McDaniel, Jan 22, 2014
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Mpouras

    Re: sys call length limitation

    George Mpouras, Jan 22, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    64
    George Mpouras
    Jan 22, 2014
  2. Rainer Weikusat

    Re: sys call length limitation

    Rainer Weikusat, Jan 22, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    69
    Rainer Weikusat
    Jan 22, 2014
  3. Rainer Weikusat

    Re: sys call length limitation

    Rainer Weikusat, Jan 22, 2014, in forum: Perl Misc
    Replies:
    2
    Views:
    69
    Peter J. Holzer
    Jan 23, 2014
  4. Rainer Weikusat

    Re: [OT] sys call length limitation

    Rainer Weikusat, Jan 24, 2014, in forum: Perl Misc
    Replies:
    1
    Views:
    87
    Rainer Weikusat
    Jan 24, 2014
  5. gamo
    Replies:
    22
    Views:
    149
    Rainer Weikusat
    Jan 26, 2014
Loading...

Share This Page