in reply to Run and kill external programm after x seconds
Would this approach be a helpful alternative? (I ask because I'm not sure I entirely understand your real problem space.)
use strict; use warnings; #1176332 my $cmd_1 = "perl D:/_scratch/1176332p2.pl"; # (renamed from OP's hel +lo.pl) open (CMD, "$cmd_1 2>&1|") or warn ("!!! Can't run program: $!\n"); while (my $line = <CMD>) { print $line; if ($line =~ m/^xyz/) { print "\n Pretending to do some string manipulation\n"; } else { print "(from $0): Nothing yet | "; } } close CMD;
use strict; use warnings; # D:/_scratch/1176332p2.pl $| = 1; print "Hello World from 1176332 PART 2\n"; print "Sleeping 10 seconds \n"; for (1 .. 10) { sleep 1; print ". \n"; } print "xyz \n";
Execution:
D:\_scratch>D:\_scratch\1176332.pl Hello World from 1176332 PART 2 (from D:\_scratch\1176332.pl): Nothing yet | Sleeping 10 seconds (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | . (from D:\_scratch\1176332.pl): Nothing yet | xyz Pretending to do some string manipulation D:\_scratch>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Run and kill external programm after x seconds
by GotToBTru (Prior) on Nov 22, 2016 at 21:03 UTC | |
Re^2: Run and kill external programm after x seconds
by demichi (Beadle) on Nov 22, 2016 at 14:13 UTC | |
by ww (Archbishop) on Nov 22, 2016 at 16:30 UTC |
In Section
Seekers of Perl Wisdom