#!/usr/bin/perl sub process_scheme{ my ($cmd, $output_file) = @_; open (OUTPUT_FILE, ">", $output_file) || die "cannot open log file"; my $scheme_pid = open (WORKER, "$cmd |") || die "cannot pipe worker"; my $str; while (1) { if (eof(WORKER)){ close WORKER; close OUTPUT; return 1; } eval{ local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm 1; $str = ; alarm 0; }; if ($@) { close OUTPUT_FILE; close WORKER; return 0; } print OUTPUT_FILE $str; } } my $code = '$|=1; my $t=2; for (1..100) { printf "%.1f\n", $_*$t; select undef,undef,undef,$t; }'; my $cmd = "perl -e '$code'"; process_scheme($cmd, "test.out");