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


I would like to call an external programm (on Windows, Perl v 5.10.0 and cannot update or install modules - I use 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.

use strict; use warnings; my $cmd_1 = "perl"; 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;

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