http://qs1969.pair.com?node_id=1176332

demichi has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I would like to call an external programm (on Windows, Perl v 5.10.0 and cannot update or install modules - I use hello.pl as example), capture the output into a var and kill the programm if it does not come back withhin e.g. 60 seconds (and go on with my perl script after the kill). Especially the killing part is the challenge for me and do not know how to solve it the best way.

test.pl

use strict; use warnings; my $cmd_1 = "perl hello.pl"; open (CMD, "$cmd_1 2>&1|") or warn ("!!! Can't run program: $!\n"); while (my $line = <CMD>) { print $line; #if ($line =~ m/^xyz/) #{ # # do some string manipulation and write it to another file #} } close CMD;

hello.pl

use strict; use warnings; $| = 1; print "Hello World\n"; print "Sleeping 1000 seconds\n"; for (1 .. 1000) { sleep 1; print ".\n"; }

I already had a look into a few examples with Win32::Process and the killing works fine with that but did not get the output captured (stdout/stderr). Thanks for any help, hints and code examples.

kind regards de Michi