For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > July 2004 > How to retreive a command's output, monitor execution time and kill it









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2004-07-14, 3:57 pm

Xref: kermit comp.lang.perl.modules:45450

Hi,
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
atall.

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

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.

Thanks,
David.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com