How to retreive a command's output, monitor execution time and kill it
From: david (removethisdavid.petruescu_at_windspring.com)
Date: 07/14/04
- Next message: Andy Stevenson: "Re: error: requires explicit package name useing DBI"
- Previous message: david: "Re: How to solve memory problems while running a script parsing huge data"
- Next in thread: Joe Smith: "Re: How to retreive a command's output, monitor execution time and kill it"
- Reply: Joe Smith: "Re: How to retreive a command's output, monitor execution time and kill it"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 14 Jul 2004 11:16:25 -0700
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.
- Next message: Andy Stevenson: "Re: error: requires explicit package name useing DBI"
- Previous message: david: "Re: How to solve memory problems while running a script parsing huge data"
- Next in thread: Joe Smith: "Re: How to retreive a command's output, monitor execution time and kill it"
- Reply: Joe Smith: "Re: How to retreive a command's output, monitor execution time and kill it"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|