in reply to streaming output to a socket

open a pipe and read from it...
$ perl -e'open F,"for f in a b c; do date; sleep 1; done |" or die $!; + while (<F>){ print } close F;' Wed Oct 13 08:01:27 PDT 2004 Wed Oct 13 08:01:28 PDT 2004 Wed Oct 13 08:01:29 PDT 2004 $
instead of having the client print to stdout, just print it to the socket

perl -e"\$_=qq/nwdd\x7F^n\x7Flm{{llql0}qs\x14/;s/./chr(ord$&^30)/ge;print"

Replies are listed 'Best First'.
Re^2: streaming output to a socket
by ikegami (Patriarch) on Oct 13, 2004 at 15:22 UTC

    Here's the same code, reformatted into context:

    # Beware of using input from the user in $cmd. my $cmd = 'for f in a b c; do date; sleep 1; done'; while (my $conn = $sock->accept()) { open(PROG, "$cmd|" or die $!; while (<PROG>) { $conn->print($_); } close(PROG); }

    If you need to send stuff to $cmd's STDIN, check out the IPC::Open2 and IPC::Open3 modules (included with perl) as an alternative to open ...|.

      Thanks I've been trying to work this out and this is clear. Thanks again.