in reply to Re^2: Executing Commands with "open"
in thread Executing Commands with "open"

Where is this buffer??

It's part of the system file handle.

Doesnt it count as memory?

It holds data, so it's some form of memory by definition.

But it's a rather small (64k?), fixed-size buffer.

So according to what you said the output is stored in this buffer. Backticks empty them into a scalar all at once.

No. That would require the output of the child to fit in the buffer, but that's impossible since it's a fixed-size buffer. Backticks repeatedly and continually empty the pipe into a scalar. Backticks is more or less equivalent to

my $pid = open(my $fh, '-|', $cmd); my $scalar = ''; 1 while sysread($fh, $scalar, BLK_SIZE, length($scalar)); waitpid($pid, 0); return $scalar;

The scalar keep growing and growing.

Update: Added the first two answers.

Replies are listed 'Best First'.
Re^4: Executing Commands with "open"
by BrowserUk (Patriarch) on Jun 14, 2010 at 18:29 UTC
    (64k?)

    Seems to be 12k?

    C:\>perl -E"$s='x'x1024; say $s, warn $_ for 1 .. 100" | perl -nle" sl +eep 100" 1 at -e line 1. 2 at -e line 1. 3 at -e line 1. 4 at -e line 1. 5 at -e line 1. 6 at -e line 1. 7 at -e line 1. 8 at -e line 1. 9 at -e line 1. 10 at -e line 1. 11 at -e line 1. 12 at -e line 1.

    Update: I think 4K at each end and 4k in the middle.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      There's a couple of problems with your code (buffering, sending 1025 or 1026 bytes at a time, -n absorbs some of the bytes).

      On this Debian system:

      $ perl -e'$|=1; { print("x"x1024); warn(++$i); redo }' | perl -e sleep ... 60 at -e line 1. 61 at -e line 1. 62 at -e line 1. 63 at -e line 1. 64 at -e line 1. [blocks] ^C
Re^4: Executing Commands with "open"
by abhijithtk (Novice) on Jun 14, 2010 at 18:40 UTC
    Thanks Guys..

    Sort of Making Sense now...