How to retreive a command's output, monitor execution time and kill it

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am writing a script where in an executable (.exe) is triggered from within
the code and the output of this is captured as a string into a variable.
Sometimes this script takes more time than expected. So, I need to monitor
the execution process and if timed out, I need to kill it. The executable is
called in a loop, so if once the executable is triggered, my code waits till
it finishes execution and then the loop is iterated.

I have 2 issues regarding this.
1. The executable returns output in a string form. I need to capture this
string. If the executable were to run from the command line, it would be
"executable.exe -$arg1 $arg2 >>result.csv"

From within the code, I would write
$result = `executable.exe -$arg1 $arg2`;

The second approach works fine but to monitor the process, I tried using
perl mdules as follows

use Proc::Background;
timeout_system($seconds, "executable.exe $arg1 >>result.csv");
and also....
my $proc2 = Proc::Background->new("$command $arg1 >> result.csv");

Since timeout_system returns exit status and not the result of  my
executable I tried redirecting my command's output into a file. Though the
above 2 statements ran successfully, the file result.csv is not created

I tried using Win32::Process too but this also did not create the result.csv

Could anyone suggest how I can monitor the execution time and also capture
the result of the executable?

2. Second issue is that the solution for the above issue has to be portable
one. I use ActiveState PERL and I need to run the same script in Windows.
Linux etc. Win32::Process is for Windows only. Proc::Simple is not available
in ActiveState PPM.

Please respond at the earliest.


Re: How to retreive a command's output, monitor execution time andkill it

Newsgroups: comp.lang.perl.modules
Subject: Re: LWP::Simple mirror destroys links
From: (Randal L. Schwartz)
Date: 16 Jul 2004 13:40:59 -0700
Lines: 19
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: 1090010907 (16 Jul 2004 15:48:27
Organization: 100,000+ UNCENSORED
Newsgroups. The #1 Usenet Service on the Planet!
X-Comments: This message was posted through's, FREE  publicly
accessible Usenet Server   -  ""
X-Comments2: IMPORTANT: does not condone, nor support,  spam or any
illegal or copyrighted postings.
X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal
or copyrighted material through this service be tolerated!!
X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the
Xref: core-easynews comp.lang.perl.modules:50924

Site Timeline