Skip to content
ggodart edited this page Jan 1, 2021 · 3 revisions

Process_Item

See original

SYNOPSIS

  my $slashdot_news = "$Pgm_Root/data/web/slashdot_news.txt";
  $p_slashdot_news = new Process_Item("get_slashdot_news > $slashdot_news");
  start $p_slashdot_news if time_now('6:30 AM');
  display $slashdot_news if done_now $p_slashdot_news;

  $p_report_weblog = new Process_Item;
  $p_report_weblog ->set_output("$config_parms{data_dir}/weblog_results.txt");
  if (time_now '2 AM') {
      set   $p_report_weblog "report_weblog /mh/data/logs/server.$Year_Month_Now.log";
      start $p_report_weblog;
  }

Example of multiple commands

  $test_process1 = new Process_Item;
  set $test_process1 'sleep 1', 'sleep 2';
  add $test_process1 'sleep 1';

Example of running an internal MisterHouse subroutine

$v_test_ftp = new Voice_Cmd 'Test background ftp [get,put]'; 
$p_test_ftp = new Process_Item; 

if ($state = said $v_test_ftp) { 
    set $p_test_ftp "&main::net_ftp(file => '/tmp/junk1.txt', " . "file_remote => 'incoming/junk1.txt'," . "command => '$state')"; 
    set_timeout $p_test_ftpb 60*2; 
    start $p_test_ftpb; 
} 
print_log "Ftp command done" if done_now $p_test_ftp;

More examples are in mh/code/examples/test_process.pl

DESCRIPTION

You can use this object to run external programs. On Win32 systems, the Win32::Process function is used. On Unix systems, the fork function is used. On either system, the following methods work in the same way:

INHERITS

Items.mht

METHODS

Method Description
new('program1 arguments', 'program2 arguments', ...)
set('program1 arguments', 'program2 arguments', ...)
set_timeout($timeout) Process will timeout after $timeout seconds
set_output($output_file) Program STDOUT errata goes to $output_file
set_errlog($errlog_file) Program STDERR errata goes to $errlog_file
add('program3 arguments', 'program4 arguments', ...) If you specify more than one program, they are run sequentially. done_now returns 1 after the last program is done. If program starts with &, then 'program arguments' is eval-ed as an internal MisterHouse function. Otherwise, 'program arguments' is run as an external command. On Windows, the &-> eval trick is supposed to work with perl 5.6+ (which has fork), but unfortunately, it causes perl to crash often, so is probably not useful yet.
start(OptionalArguements) Starts the process with optional program arguments
done Returns the time (seconds since epoch) that the process finished. If the process has been started, but has not yet finished, it returns 0.
pid Returns the process id
timed_out Returns the time when the process timed out. done_now will still trigger for a timed_out process.
done_now Is true for the pass that the process finished on.
stop Stops the process. If called as a stand alone function (not as an object method), all active Process_Items are stopped.
nice_level Support for setting "nice" level; only useful for *nix
get_type() Returns the class (or type, in Misterhouse terminology) of this item.

INI PARAMETERS

NONE

AUTHOR

UNK

SEE ALSO

NONE

Clone this wiki locally