#!perl $program = "c:\\progdir\\bin\\proggie.exe"; $dstfile = "d:\\scripts\\log\\archive\\proggie.log"; $arg0 = "\"Blah.Blech.>\""; $timeout = 60; $starttime = time; open( PRG, "$program $arg0 |") || die "Couldn't open PRG: $!\n"; open (LF, ">$finaldest"); while () { print LF "$_"; $difftime = time - $starttime; last if ($difftime > $timeout); } close (LF); close (PRG); #### #!perl use strict; # ALWAYS! (Why? Helps catch typos before run time... among other things) $|=1; # This disables buffering. JCWren's Suggestion. my $program = 'c:\progdir\bin\proggie.exe'; my $dstfile = 'd:\scripts\log\archive\proggie.log'; my $arg0 = '"Blah.Blech.>"'; my $timeout = 60; open( PRG, "$program $arg0 |") or die "Couldn't open '$program $arg0', $!"; open(LF, ">$finaldest") or die $!; my $inloop = 0; my $endtime = time + $timeout; # Only do the math once. while( and $endtime >= time ) # '>=' or '>', your choice. { if( not $inloop ) { # This will get run the first time, but not after. # As per JCWren's Suggestion. print STDERR "Inside Loop\n"; $inloop = 1; } chomp; print LF $_, "\n"; } close(LF) or die $!; close(PRG) or die $!; #### C:\>perl -we "$i=0;$stop=time +2;while(1){print $i++, qq!\n!; last if time > $stop}"