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 ...|.
In reply to Re^2: streaming output to a socket
by ikegami
in thread streaming output to a socket
by Scarborough
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |