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

From: david (removethisdavid.petruescu_at_windspring.com)
Date: 07/14/04


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.



Relevant Pages

  • Re: Slow string
    ... I see virtually no difference in execution time for the code you posted when using cscript versus using wscript; to confirm, I bracketed the code with an initial ... Are you actually entering the script name into a console window? ... You can use the exact same line for every wrapper script - and that includes wsf and js scripts; all you need to do is change the final "vbs" to "wsf" or "js" as appropriate. ... If you build a large string by small concatenations, the performance degrades geometrically - so does array resizing, because they both use the same nasty technique inherited from VB1 of copying the entire data structure to a new structure with the added element. ...
    (microsoft.public.scripting.vbscript)
  • Re: MATLAB Code for a stop process button which ex
    ... especially in the while loop(for each script command starting in the ... % varargin command line arguments to stop_button ... % line_num is the order of execution. ... msgno = msgno+1; ...
    (comp.soft-sys.matlab)
  • Re: CGI Scripts
    ... the URL to have "Scripts and Executables" execution permission, ... script by their respective script engines, and all URLs that are .COM, .EXE, ... If you make a request to the CGI script and you get the download dialog, ...
    (microsoft.public.inetserver.iis.security)
  • Creating a waitbar
    ... opens up with Stop processing..the script gets executed... ... % A data structure containing a field of matlab commands 'scriptcmds' ... % line_num is the order of execution. ...
    (comp.soft-sys.matlab)
  • [Full-disclosure] Original Photo Gallery Remote Command Execution
    ... The systems consist of two parts: "a client side script to scale your ... Upgrade to the new version 0.11.3 witch fix this vulnerability. ... Disable execution using disable_functions in php.ini. ... VENDOR RESPONSE ...
    (Full-Disclosure)